<strong>Possible Duplicate:</strong><br /><a href="https://stackoverflow.com/questions/1661273/floating-point-arithmetic-not-producing-exact-results-in-java" rel="nofollow">Floating point arithmetic not producing exact results in Java</a></blockquote>
I was recently working on a project when I came across a strange bug.
When 2 was subtracted from 65.12 the value was greater (not equal to) 63.12.
Here's the simplified code:
And the output in the console:
I'm not sure why this is the case and if anyone knows a simple fix/workaround that would be great!
It has to do with the way floating-point values are handled by computers. The recommended text for fully understanding the topic is: <a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" rel="nofollow">What Every Computer Scientist Should Know About Floating-Point Arithmetic</a>