From 53f4685e67142e234a4ccf4f01fd96228de855b7 Mon Sep 17 00:00:00 2001 From: Tom Picton Date: Tue, 22 Oct 2019 09:47:59 -0700 Subject: [PATCH] Fix round function failing on Decimal objects --- src/future/builtins/newround.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/future/builtins/newround.py b/src/future/builtins/newround.py index 3943ebb6..b0e6a001 100644 --- a/src/future/builtins/newround.py +++ b/src/future/builtins/newround.py @@ -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)