为什么“十进制。十进制在Python 2.6.5中,('0')<1.0“产生False

2024-03-28 14:30:16 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python 2.6.5中,以下表达式产生False:

>>> import decimal
>>> decimal.Decimal('0') < 1.0
False

有没有理由解释十进制和浮点的比较应该是这样的呢?在


Tags: importfalse表达式浮点decimal理由
1条回答
网友
1楼 · 发布于 2024-03-28 14:30:16

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. In earlier versions x < y returned the same (arbitrary) result for any Decimal instance x and any float instance y.

所以看起来这是一个bug/缺失的特性,你需要做的就是升级。在

相关问题 更多 >