Skip to content

Commit

Permalink
Merge pull request #517 from tpict/master
Browse files Browse the repository at this point in the history
Fix round function failing on Decimal objects
  • Loading branch information
jmadler authored Oct 24, 2019
2 parents d7f20ce + 53f4685 commit ac0b29a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/future/builtins/newround.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ def newround(number, ndigits=None):
if 'numpy' in repr(type(number)):
number = float(number)

if not PY26:
d = Decimal.from_float(number).quantize(exponent,
rounding=ROUND_HALF_EVEN)
if isinstance(d, Decimal):
d = number
else:
d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN)
if not PY26:
d = Decimal.from_float(number).quantize(exponent,
rounding=ROUND_HALF_EVEN)
else:
d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN)

if return_int:
return int(d)
Expand Down

0 comments on commit ac0b29a

Please sign in to comment.