powershellcsvnumbersmultiplication

Multiplying 2 values gives the original value but dividing the same values gives the right answer


I have 2 values that I can not get to multiply together and get the right answer. Here is my very simple code:

$data | ForEach-Object {
            $newMHV = ($_.'North' * $_.'Measured Heat Value') 
            $_.'North BTU' = $newMHV
            $_               # Output the modified row
            } | Export-Csv $AFw -NoTypeInformation

The first time through the loop $_.'North' = 1648 and $_.'Measured Heat Value' = 1.022 $newMHV should be 1684.xxx. $newMVH always shows 1648 on the first value then changes to the second value.

When I change the calculation to division, I get the correct value.

I have tried trimming the values, etc. but I cant find it. I may need to convert them to a numeric but why would it work when I divide the values?

Note: $data is a .csv file that I have imported.


Solution

  • The crucial pointer is in the comments:

    $newMHV = [double] $_.'North' * $_.'Measured Heat Value'
    

    As for what you tried:


    [1] It follows that if $n is 1, you get (an identical copy of) the string itself, and if it is 0, you get the empty string ('').