# Decimal vs Float comparasion

Discussion in 'Python' started by Yuan HOng, May 6, 2008.

1. ### Yuan HOngGuest

Hi,

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.

--
Hong Yuan

´ó¹Ü¼ÒÍøÉÏ½¨²Ä³¬ÊÐ
×°ÐÞ×°äê½¨²ÄÒ»Õ¾Ê½¹ºÎï
http://www.homemaster.cn

Yuan HOng, May 6, 2008

2. ### GastoGuest

I still don't see why such a module exists.

On 5 mayo, 21:52, "Yuan HOng" <> wrote:
> Hi,
>
> 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.
>
> --
> Hong Yuan
>
> ´ó¹Ü¼ÒÍøÉÏ½¨²Ä³¬ÊÐ
> ×°ÐÞ×°äê½¨²ÄÒ»Õ¾Ê½¹ºÎïhttp://www.homemaster.cn

Gasto, May 6, 2008

3. ### Marco MarianiGuest

Gasto wrote:

> I still don't see why such a module exists.

There are 2.0 types of programmers: those who always use floating point,
and those who know how to use them.

Marco Mariani, May 6, 2008
4. ### RhamphoryncusGuest

On May 6, 1:31 am, Dennis Lee Bieber <> wrote:
> On Tue, 6 May 2008 11:52:10 +0800, "Yuan HOng" <>
> declaimed the following in comp.lang.python:
>
>
>
> > 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.

>
> Why should decimal be coerced to float? Maybe float should be
> coerced to decimal?
>
> Or... the programmer should explicitly specify what comparison is
> wanted -- if any...
>
> Or... Isn't Python 3.x supposed to forbid mixed type comparisons
> unless the types implement suitable handling?

Yes, it is fixed in 3.0. Unfortunately it's well established
behaviour in 2.x, so it won't be changing there. Don't bother