Grzegorz Jakacki
Grzegorz Jakacki

Reputation: 201

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?

Upvotes: 5

Views: 418

Answers (1)

Michael Borgwardt
Michael Borgwardt

Reputation: 346526

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.

Upvotes: 13

Related Questions