Comparing float and decimal

D'Arcy J.M. Cain darcy at druid.net
Tue Sep 23 07:20:12 EDT 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
True
>>> i == d
True
>>> f == d
False

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 druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list