Decimal vs Float comparasion
Wojciech Walczak
wojtek.gminick.walczak at gmail.com
Tue May 6 02:32:03 EDT 2008
2008/5/6, Yuan HOng <hongyuan1306 at gmail.com>:
> It seems decimal object will always be larger than float in
> comparasion, which goes against common sense:
>
> >>> from decimal import Decimal
> >>> a = Decimal('0.5')
> >>> a > 99999
> False
> >>> a > 99999.0
> True
>
> It seems to me that rather than allowing this to happen, comparasion
> between the two should either be made correct (by convertion decimal
> to float e.g.) or forbidden, like arithmatic operations between the
> two types.
Looks like a nasty bug.
a > 99999.0 returns True because NotImplemented > 99999.0 returns True.
a < 99999.0 returns False because NotImplemented < 99999.0 returns False.
As you can see the real comparision has nothing to do with your Decimal number.
I think you can report it at bugs.python.org.
--
Regards,
Wojtek Walczak
http://www.stud.umk.pl/~wojtekwa/
More information about the Python-list
mailing list