Comparing float and decimal

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Sep 24 00:21:10 EDT 2008


On Tue, 23 Sep 2008 07:08:07 -0700, Michael Palmer wrote:

>> > 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.
>>
>> I don't see why transitivity should apply to Python objects in general.
> 
> Well, for numbers it surely would be a nice touch, wouldn't it. May be
> the reason for Decimal to accept float arguments is that irrational
> numbers or very long rational numbers cannot be converted to a Decimal
> without rounding error, and Decimal doesn't want any part of it. Seems
> pointless to me, though.

Is 0.1 a very long number?  Would you expect ``0.1 == Decimal('0.1')`` to 
be `True` or `False` given that 0.1 actually is

In [98]: '%.50f' % 0.1
Out[98]: '0.10000000000000000555111512312578270211815834045410'

?

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list