Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "decimal.Decimal('0') < 1.0" yields False in Python 2.6.5

In Python 2.6.5 the following expression yields False:

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

Is there a rationale explaining why comparison of Decimal against float should behave like this?

like image 886
Grzegorz Jakacki Avatar asked Feb 09 '11 13:02

Grzegorz Jakacki


1 Answers

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

So it looks like that was a bug/missing feature and all you need to do is upgrade.

like image 90
Michael Borgwardt Avatar answered Oct 13 '22 18:10

Michael Borgwardt