Issue 1650053: decimals compare badly to floats (original) (raw)
Issue1650053
Created on 2007-02-01 18:20 by jinty_, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg31160 - (view) | Author: Brian Sutherland (jinty_) | Date: 2007-02-01 18:20 |
This behaviour is so unexpected that I'm pretty sure it's a bug. If decimals can't be compared to floats, at least it should error. Found in python2.4 and 2.5 by at least 2 people: Python 2.5 (release25-maint, Dec 9 2006, 14:35:53) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from decimal import Decimal >>> 1172837167.27 > Decimal("1172837136.0800") False >>> 1172837167.27 > Decimal("1") False | ||
msg31161 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2007-02-01 20:24 |
It was intended that Decimals not be compared to floats, but I think we can do better than returning a useless result | ||
msg31162 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2007-02-12 07:40 |
The __cmp__() method decimal.py is doing the right thing and returning NotImplemented. The odd result you're seeing is just Python's normal way of handling things it doesn't know how to compare. You get the same results by comparing floats to strings: >>> 1172837167.27 > "1172837136.0800" False >>> 1172837167.27 > "1" False I don't see a way to change this behavior without making deep incompatible changes to Python. If someone sees a way out, feel free to re-open this bug. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:22 | admin | set | github: 44537 |
2007-02-01 18:20:59 | jinty_ | create |