PowerShell math wrong -
why powershell seem give me wrong answers when answer between 0 , 1?
ps c:\users\me> 31.2 - 31 0.199999999999999 <<< wrong ps c:\users\me> 31.2 - 30 1.2 <<< right ps c:\users\me> 31.2 % 10 1.2 <<< right ps c:\users\me> 30.2 % 10 0.199999999999999 <<< wrong ps c:\users\me> 30.2 / 151 0.2 <<< right
you need use [decimal] man-in-the-street math.
[decimal]31.2 - [decimal]31
or
31.2d - 31
numeric literals default double, can't represent many decimals (because require repeating fractions, involve rounding errors, etc)
ref: https://devcentral.f5.com/articles/powershell-abcs-t-is-for-type-literals
Comments
Post a Comment