Incorrect Decimal-Float behaviour in comparison tests
fredrik at pythonware.com
Fri Mar 3 17:53:41 CET 2006
"Cassiano, Marco" wrote:
> I have difficulties with a weird Python 2.4.2 behaviour in comparing
> Decimal to Floats.
> For Example :
> >>> from decimal import Decimal
> >>> a=Decimal('3.7')
> >>> b=6.3
> >>> if a > b :print a,b,'a is greater than b - NOT TRUE!!!!'
> ... else: print a,b,'b is greater than a - CORRECT'
> 3.7 6.3 a is greater than b - NOT TRUE!!!!
>>> 1.0 > "0"
also a bug ?
"Most other types compare unequal unless they are the
same object; the choice whether one object is considered
smaller or larger than another one is made arbitrarily but
consistently within one execution of a program."
you can find more information on the design of the decimal type
and various issues with floating point are described here:
More information about the Python-list