Convert Scientific notation to decimal in .csv with Powershell Script

Viewed 45

I'm trying to write a Powershell script that converts all scientific notations in a csv file to decimal.

For that :

$list = Import-CSV -Path .\this.csv -Delimiter ";" -Encoding UTF8
foreach($col in $list){
        $col.price = $col.price -as [double]
        Write-Output $col.price
}

But the results of this do not change the output strings.

Any solution ?

Thx. Etienne

1 Answers

Here I wrote an example CSV as there was no example provided

"Name;Price
1;123.4E+03
2;1.666E-08" | Out-File this.csv

This is the new version of your code that gets the CSV Then for the output I selected 2 columns (Name,Price) and redefined what the content of price should be.

$list = Import-CSV -Path .\this.csv -Delimiter ";" -Encoding UTF8
$list | Select-Object Name,@{Name="Price";expression={$_.Price -as [Decimal]}}

The output looks like that:

Name         Price
----         -----
1           123400
2    0,00000001666

If it does not work with your CSV, then please share an example.

Related