考虑以下几点:这是Python 2.7.1中的一个数字比较中的错误吗?
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 2.0
>>> print x < 2.0
False
>>>
>>> x = 2.2
>>> x -= 0.2
>>> print x < 2.0
False
>>>
>>> x = 2.4
>>> x -= 0.2
>>> x -= 0.2
>>> print x < 2.0
True
>>> print x
2.0
为什么二号的最后一条语句打印真正的从2.4到2.0,当x减少?我错过了什么?
浮点错误熊。 (请参阅[这里](http://stackoverflow.com/questions/588004/is-javascripts-floating-point-math-broken)了解JavaScript的等价物)。 – 2013-03-05 07:37:15
[浮点运算可能不准确](http://docs.python.org/2/tutorial/floatingpoint.html) – Volatility 2013-03-05 07:37:24