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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -