0

Why trunc(4.9999999999999999) ==5, but trunc(4.999999999999999) ==4?

user66380
  • 9
  • 2
  • 3
    At double-precision, 4.9999999999999999 is indistinguishable from 5. – Rufflewind Jan 13 '16 at 19:22
  • Totally unrelated to the other question. Most languages have a rule that a floating point number in decimal notation will be converted to the nearest possible floating point number. The first number has one digit '9' more, which makes 5 the nearest possible floating point number, while in the second case there is a floating point number slightly less than 5 that is nearer. Of course trunc (5) = 5, but trunc ("slightly less than 5") = 4. – gnasher729 Jan 14 '16 at 09:08
  • 1
    I don't think this is a duplicate. While it is certainly *related*, and the cause the same, the question itself is *completely different*. – Darkhogg Jan 14 '16 at 09:49

0 Answers0