Skip to content

Commit 53f4685

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

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/future/builtins/newround.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ 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)
41+
if isinstance(d, Decimal):
42+
d = number
4443
else:
45-
d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN)
44+
if not PY26:
45+
d = Decimal.from_float(number).quantize(exponent,
46+
rounding=ROUND_HALF_EVEN)
47+
else:
48+
d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN)
4649

4750
if return_int:
4851
return int(d)

0 commit comments

Comments
 (0)