see comments in code. u can see when 55.5000 is calculated, it rounds to 55.
Then i assign the value manually to 55.5000, and it rounds properly to 56.
There is no 55.5000 calculated in code.
It just seems that way because you so not have enough precision. change line 5 to have 16 digit precision and see for yourself.
thanks. you're right, i get a leftover of leftOver: 55.4999999999999720.
this leads to my follow up:
why is (42.555 - 42.0000000000000000)*100 equal to the above?
ok, read some of it. From what I can understand numbers like .1 can't be represented in exact values in binary, unlike base 10. So what's the solution? Is there a rule of thumb for avoiding this kind of error. How should I fix the code to avoid this error.