in reply to Re^2: Decimal numbers calculations done inconsistently: Odd behavior!
in thread Decimal numbers calculations done inconsistently: Odd behavior!

That may be slightly more complicated than that. IEEE Standard rounding rules are somewhat unexpected to many people. This is what true rounding is supposed to be according to IEEE:
$ perl -e 'my $c = 0.5; $c +=1 and printf "%f -> %0.0f\n", $c, $c for +1..10;' 1.500000 -> 2 2.500000 -> 2 3.500000 -> 4 4.500000 -> 4 5.500000 -> 6 6.500000 -> 6 7.500000 -> 8 8.500000 -> 8 9.500000 -> 10 10.500000 -> 10
Round up if the previous digit is odd and round down if it is even.

Je suis Charlie.
  • Comment on Re^3: Decimal numbers calculations done inconsistently: Odd behavior!
  • Download Code