Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:30:47+00:00 2026-05-13T23:30:47+00:00

This is somehow related to my question Why is ”>0 True in Python? In

  • 0

This is somehow related to my question Why is ”>0 True in Python?

In Python 2.6.4:

>> Decimal('0') > 9999.0
True

From the answer to my original question I understand that when comparing objects of different types in Python 2.x the types are ordered by their name. But in this case:

>> type(Decimal('0')).__name__ > type(9999.0).__name__
False

Why is Decimal('0') > 9999.0 == True then?

UPDATE: I usually work on Ubuntu (Linux 2.6.31-20-generic #57-Ubuntu SMP Mon Feb 8 09:05:19 UTC 2010 i686 GNU/Linux, Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2). On Windows (WinXP Professional SP3, Python 2.6.4 (r264:75706, Nov 3 2009, 13:23:17) [MSC v.1500 32 bit (Intel)] on win32) my original statement works differently:

>> Decimal('0') > 9999.0
False

I even more puzzled now. %-(

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:30:48+00:00Added an answer on May 13, 2026 at 11:30 pm

    Because the decimal module does not compare against any type except long, int, and Decimal. In all other cases, decimal silently returns the “not something it knows about object” as greater. You can see this behavior in the _convert_other() function of decimal.py

    Silly, silly Decimal class.

    Oh, see http://bugs.python.org/issue2531 as well.

    So, here is what happens:

    • The interpreter calls the Decimal.__gt__ comparison function.
    • Decimal.__gt__ calls Decimal._convert_other to convert the incoming float to a Decimal.
    • Decimal._convert_other doesn’t understand floats. The implementation down in Decimal._convert_other
      explicitly checks for long, int, and Decimal types of the operand. Yes, this is
      a bug, in that unexpected library implementations cause bugs further down the line. It
      would be cleaner to do the right thing or even just through a TypeException. Instead
      it throughs the same NotImplemented that would happen comparing a Decimal to, say,
      a hash of Employee records.
    • A few other comparison operations are tried. Comparison gives up.
    • The default comparison, down in CPython’s Objects/object.c/default_3way_compare get called.
    • In Python 3, this rightly barfs. In Python 2, it compares the id() functions.
    • On Windows, a case insensitive comparison is used (sort of). On modern systems, a
      case sensitive comparison is used.
    • So you get different results.

    Are we there yet?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question somehow addresses the problem, but not from the side I'm looking for.
This is somehow related to question about big strings and PEP8 . How can
This is somehow related to my question here . I process tons of texts
So, i recently found this term related somehow to neural networks, but I don't
Is this possible somehow to generate a GUID in C#, that mostly corresponds to
This question is somehow similar to the ones about how to make ARC and
Today, during some other somehow related work, came across my mind the following question:
This question is picking up from the following thread on the (now read-only) OpenRasta
Looking through PIL (and related to this question ), where can I get a
This question is related to this other question I recently asked... cf.net exception and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.