I want to subtract a negative int
from a float
in javascript:
10.1 - 9
I expected the output to be:
1.1
What I get is:
1.0999999999999996
I get this result in all browsers I have tested (latest Safari, Chrome & Firefox). I tried to convert the int to a float (9.0
) or change the order (-9 + 10.1
), but it remains the same.
Positive numbers work as expected. Only the negative numbers are affected.
Is there any explanation to this and is it possible to fix this behavior without rounding the result?