D'Arcy J.M. Cain wrote:
I can give you the technical answer after reading the sources of the
decimal module: you can only compare to Decimal what can be converted to
Decimal. And that is int, long and another Decimal.
Everything else will return False when comparing.
Yes, but only if comparison from type(A) to type(C) is supported at all.
Instead of raising ValueError or NotImplementedE rror, the decimal
module returns False here.
-- Gerhard
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?
>
True
True
False
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 = 10
>>>f = 10.0
>>>d = Decimal("10.00" )
>>>i == f
>>>i == d
>>>f == d
decimal module: you can only compare to Decimal what can be converted to
Decimal. And that is int, long and another Decimal.
Everything else will return False when comparing.
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.
C then A is equal to C.
Instead of raising ValueError or NotImplementedE rror, the decimal
module returns False here.
-- Gerhard