Decimal vs Float comparasion

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

  1. Yuan HOng

    Yuan HOng Guest

    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
    #1
    1. Advertising

  2. Yuan HOng

    Gasto Guest

    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
    #2
    1. Advertising

  3. 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
    #3
  4. 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
    reporting a bug about this unless it's about 3.0.
     
    Rhamphoryncus, May 6, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bd
    Replies:
    0
    Views:
    634
  2. Ven
    Replies:
    3
    Views:
    1,327
  3. Yuan HOng

    Locale-specific string comparasion

    Yuan HOng, Jul 26, 2007, in forum: Python
    Replies:
    0
    Views:
    276
    Yuan HOng
    Jul 26, 2007
  4. Carsten Fuchs
    Replies:
    45
    Views:
    1,554
    James Kanze
    Oct 8, 2009
  5. Tobias Weber
    Replies:
    10
    Views:
    178
    Tobias Weber
    May 27, 2008
Loading...

Share This Page