0

I'm using Kotlin 1.2, JVM target 1.8 on a Mac on Intellij IDEA 2018.2.

I am seeing very strange behavior when multiplying doubles with multiples of 9.enter image description here

For anybody who is curious, this result should be 1.35. This error happens without debugging as well, and is adding up for me over multiple runs. I can get around it by using 1.5*9 and then just dividing by 10, but does anybody know why this is happening?

Feel free to check out my sample on the kotlin website

A J
  • 1,080
  • 7
  • 11
  • Ah, so the idea is that floating point is inherently unstable after some amount of precision. I'll close this question out, I guess, but I'm about 80% sure I never saw this behavior in Java – A J Aug 17 '18 at 05:27
  • Then you have just been lucky :) – Lasse V. Karlsen Aug 17 '18 at 05:31
  • try 0.15*9.0 in any languages and **print enough fractional digits** and you'll see. Most of the fractional values in decimal can't be represented exactly in binary floating-point types – phuclv Aug 17 '18 at 05:38

0 Answers0