0

So the behavior of parseInt here seems to me to be so bad that I just don't know what to think...

parseInt(1.15*100) = 114
tadasajon
  • 14,276
  • 29
  • 92
  • 144
  • 4
    Have you examined `1.15*100` alone? Hint: `parseInt` isn't the problem. Floating-point multiplication is. – apsillers Sep 12 '14 at 19:52
  • `1.15 * 100 = 114.999999` but `1.17*100 = 117` and `1.18*100 = 118` – tadasajon Sep 12 '14 at 19:54
  • `parseInt` stringifies non-string arguments and then reads input until it encounters anything inconsistent with an integer (i.e., here, everything right of the decimal point is ignored), so we end up with `114`. – apsillers Sep 12 '14 at 19:56
  • It's very tough to express `1.15` in binary `m * 2^e` format, just like it's very tough to express the simplified form of `10/3` in decimal format. – apsillers Sep 12 '14 at 19:59

0 Answers0