[英]Why “decimal.Decimal('0') < 1.0” yields False in Python 2.6.5
In Python 2.6.5 the following expression yields False: 在Python 2.6.5中,以下表达式产生False:
>>> import decimal
>>> decimal.Decimal('0') < 1.0
False
Is there a rationale explaining why comparison of Decimal against float should behave like this? 是否有理由解释为什么Decimal与float的比较应该像这样?
From the documentation of the decimal module : 从十进制模块的文档 :
Changed in version 2.7: A comparison between a float instance x and a Decimal instance y now returns a result based on the values of x and y. 版本2.7中的更改:浮点实例x和Decimal实例y之间的比较现在返回基于x和y值的结果。 In earlier versions x < y returned the same (arbitrary) result for any Decimal instance x and any float instance y. 在早期版本中,x <y为任何Decimal实例x和任何float实例y返回相同(任意)的结果。
So it looks like that was a bug/missing feature and all you need to do is upgrade. 所以看起来这是一个错误/缺失的功能,你需要做的就是升级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.