Comparing float and decimal

D'Arcy J.M. Cain darcy at
Tue Sep 23 13:20:12 CEST 2008

I'm not sure I follow this logic.  Can someone explain why float and
integer can be compared with each other and decimal can be compared to
integer but decimal can't be compared to float?

>>> from decimal import Decimal
>>> i = 10
>>> f = 10.0
>>> d = Decimal("10.00")
>>> i == f
>>> i == d
>>> f == d

This seems to break the rule that if A is equal to B and B is equal to
C then A is equal to C.

D'Arcy J.M. Cain <darcy at>         |  Democracy is three wolves                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

More information about the Python-list mailing list