diff options
author | Raymond Hettinger <python@rcn.com> | 2004-11-24 07:28:48 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-11-24 07:28:48 (GMT) |
commit | 605ed0248375bbf87bbd1d80afc7c6918fd3ce2b (patch) | |
tree | 92c01fd62467bb05704330da04f0f4c9d468cf66 /Lib/decimal.py | |
parent | 8f2c4eed93fd0aab1fbcce1e8e57ffea358c4901 (diff) | |
download | cpython-605ed0248375bbf87bbd1d80afc7c6918fd3ce2b.zip cpython-605ed0248375bbf87bbd1d80afc7c6918fd3ce2b.tar.gz cpython-605ed0248375bbf87bbd1d80afc7c6918fd3ce2b.tar.bz2 |
SF bug #1071588 coercing decimal to int doesn't work between -1 and 1
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 6ffbd18..f9c065f 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1410,14 +1410,14 @@ class Decimal(object): return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long" - if not self: - return 0 - sign = '-'*self._sign if self._exp >= 0: - s = sign + ''.join(map(str, self._int)) + '0'*self._exp - return int(s) - s = sign + ''.join(map(str, self._int))[:self._exp] - return int(s) + s = ''.join(map(str, self._int)) + '0'*self._exp + else: + s = ''.join(map(str, self._int))[:self._exp] + if s == '': + s = '0' + sign = '-'*self._sign + return int(sign + s) def __long__(self): """Converts to a long. |