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.
|