I try to calculate the following product in python:
4.6*400
The answer should be 1840, however, python answers 1839.999....
This works fine
4.6*40*10
Is this a bug in python, or expected behaviour?
I try to calculate the following product in python:
4.6*400
The answer should be 1840, however, python answers 1839.999....
This works fine
4.6*40*10
Is this a bug in python, or expected behaviour?
This is not a bug.
>>> 1.2-1.0
0.199999999999999996
Floating point numbers only have 32 or 64 bits of precision, so the digits are cut off at some point, and the resulting number is 0.199999999999999996 in decimal, not 0.2.
For more information you can read the old Python FAQ article Why are floating point calculations so inaccurate? at effbot.org.