I have a script that converts a CSV file to an ASC formatted file with the data in specific column positions.
I am trying to take a Sales value in my array that has way too many trailing decimal places and round it to 2 decimal places and then I need it padded as well. The Sales value in the array is formatted like “354.9999999999” or “21.98” or “967.000001” etc. It’s not consistent. There are no commas in it.
Below is the existing old code where it’s currently just padding the Sales field. I need it first round the sales number and then pad to 2 decimal places.
$array = Import-csv -path $FileName.FullName -delimiter ',' -Header RecordType,Date,Time,Code,Sales,Customers,Items $arr = $array | foreach-object {$_.RecordType + ' ' + $_.Date + ' ' + $_.Time + ' ' + $_.Code.padleft(5,' ') + ' ' +$_.Sales.padleft(10,' ') + $_.Customers.padleft(5,' ') + $_.Items.padleft(5,' ') }