Skip to content

Commit ae49264

Browse files
committed
Fix round function failing on Decimal objects
1 parent a3e303f commit ae49264

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/future/builtins/newround.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ def newround(number, ndigits=None):
3838
if 'numpy' in repr(type(number)):
3939
number = float(number)
4040

41-
if not PY26:
42-
d = Decimal.from_float(number).quantize(exponent,
43-
rounding=ROUND_HALF_EVEN)
44-
else:
45-
d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN)
41+
if not isinstance(d, Decimal):
42+
if not PY26:
43+
d = Decimal.from_float(number).quantize(exponent,
44+
rounding=ROUND_HALF_EVEN)
45+
else:
46+
d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN)
4647

4748
if return_int:
4849
return int(d)

0 commit comments

Comments
 (0)