This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author annarave
Recipients
Date 2004-11-23.10:14:28
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
When trying to coerce a Decimal instance to int, it
works just fine if you have a value over 1. It does not
work for decimal values between1 and -1. For example:

>>> d
Decimal("1.1")
>>> s
Decimal("0.5")
>>> int(d)
1
>>> int(s)

Traceback (most recent call last):
  File "<pyshell#13>", line 1, in -toplevel-
    int(s)
  File "C:\Python24c1\lib\decimal.py", line 1420, in
__int__
    return int(s)
ValueError: invalid literal for int(): 
>>> n
Decimal("-0.5")
>>> int(n)

Traceback (most recent call last):
  File "<pyshell#16>", line 1, in -toplevel-
    int(n)
  File "C:\Python24c1\lib\decimal.py", line 1420, in
__int__
    return int(s)
ValueError: invalid literal for int(): -
>>> float(n)
-0.5
>>> i
Decimal("-1.5")
>>> int(i)
-1

Decimal coercion should work the same regardless of the
value. Outside this range (-1:1), it simply truncates
to the nearest integer. Inside this range, it returns a
ValueError. It should truncate to 0, to follow the way
the rest of Decimal coercion works.
History
Date User Action Args
2007-08-23 14:27:43adminlinkissue1071588 messages
2007-08-23 14:27:43admincreate