Removed unused code in django.db.backends.utils.format_number().

This commit is contained in:
Tim Graham 2018-07-02 16:10:35 -04:00 committed by GitHub
parent 0e64e046a4
commit 4009e1f2ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 11 deletions

View File

@ -225,18 +225,14 @@ def format_number(value, max_digits, decimal_places):
""" """
if value is None: if value is None:
return None return None
if isinstance(value, decimal.Decimal): context = decimal.getcontext().copy()
context = decimal.getcontext().copy() if max_digits is not None:
if max_digits is not None: context.prec = max_digits
context.prec = max_digits
if decimal_places is not None:
value = value.quantize(decimal.Decimal(1).scaleb(-decimal_places), context=context)
else:
context.traps[decimal.Rounded] = 1
value = context.create_decimal(value)
return "{:f}".format(value)
if decimal_places is not None: if decimal_places is not None:
return "%.*f" % (decimal_places, value) value = value.quantize(decimal.Decimal(1).scaleb(-decimal_places), context=context)
else:
context.traps[decimal.Rounded] = 1
value = context.create_decimal(value)
return "{:f}".format(value) return "{:f}".format(value)