I was wondering how can I subtract two negative Floating-Point numbers in javascript. I tried:
alert(-0.2-0.1);
and the result is -0.
-0.
No, nothing wrong with your code, most decimal fractions cannot be represented exactly in binary, use
number.toFixed(x)
Where x is the number of decimals you want and number is the result of the subtraction.
x
number