https://stackoverflow.com/questions/10403434/floating-point-in-python-gives-a-wrong-answer
>>> float(10.0-9.2)
0.800000000000000*7*
注意到 n*0.001 有时也会出现类似的问题,
>>> 817*0.001
0.8170000000000001
这是一个Python 内置的错误:
Floating point arithmetic has built-in problems as it's based on a binary approximation of numbers.
There is a good explanation of this in the Python docs.
You can check out the decimal
module if you need more exact answers.
采用round 可以解决这个问题。