-1

I'm doing a very basic script of sorting an employee CSV file, and renaming a couple of the fields. Easy stuff, but now I'm supposed to add a column at the end and show what the employee's 6% bonus would be. So I'm using this entry:

@{label='Bonus';expression={$_.Salary * .06}}

However..it just returns nothing. The field is blank. If I change it to show the bonus plus the salary...

@{label='BonusSalary';expression={$_.Salary * 1.06}}

It returns the Salary value, like I multiplied by one. Now if I change the operator to anything OTHER than multiplication, it works fine.

Can someone point me in the right direction to find out why it's doing this?

  • 2
    Please create a [mcve], I guess this is your issue: [not all properties displayed](https://stackoverflow.com/a/44429084/1701026) but there aren't enough details to confirm. – iRon Sep 30 '20 at 13:10

1 Answers1

1

I'm assuming this is the situation, where the left argument is a string. In that case, powershell will repeat the string that many times. The right arg actually becomes an integer. If you reverse the arguments, it will convert the right argument to a double or floating point. When you import a csv, all fields are strings. It would be different with a json file.

'1.0' * .06


.06 * '1.0'
0.06


'hi' * 3
hihihi


'1.0' * 3
1.01.01.0


[double]'10.00' * .06
0.6
js2010
  • 23,033
  • 6
  • 64
  • 66
  • You're amazing! I didn't think to flop the two because I didn't know what it was doing internally. Thank you for the explanation! – Greg Hager Sep 30 '20 at 17:08