In Python I did 3.08 - 4.31
and got back -1.2299999999999995
.
This is definitely not right (-1.23
is right) and highly concerning. I am not seeing this behavior in other languages, any insights into what Python is doing here?
In Python I did 3.08 - 4.31
and got back -1.2299999999999995
.
This is definitely not right (-1.23
is right) and highly concerning. I am not seeing this behavior in other languages, any insights into what Python is doing here?
You can find a great explanation here: https://docs.python.org/2/tutorial/floatingpoint.html
To fix this use round(3.08 - 4.31, 2)