How to achieve "1 - 1/3 - 1/3 - 1/3 = 0"?

63 views Asked by At

I want to be able to subtract 1/3 from my variable in a mathematically correct way, meaning: If a 1D is subtracted by 1/3 three times, it should be 0D.

However, I keep ending up with some tiny value (1.1102230246251565E-16)

I've already tried rounding it after each subtraction (Math.round(input*1000000.0)/1000000.0), however I end up with 0.333334 after the second subtraction, and with 1.0E-6 after the third subtraction. Why?

0

There are 0 answers