Used Decimal.scaleb() in backends.utils.format_number() and DecimalField.widget_attrs() to improve performance.

This commit is contained in:
Mariusz Felisiak 2017-12-30 18:05:15 +01:00 committed by GitHub
parent 9bc4d90d1a
commit 51a00749e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -236,7 +236,7 @@ def format_number(value, max_digits, decimal_places):
if max_digits is not None:
context.prec = max_digits
if decimal_places is not None:
value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)
value = value.quantize(decimal.Decimal(1).scaleb(-decimal_places), context=context)
else:
context.traps[decimal.Rounded] = 1
value = context.create_decimal(value)

View File

@ -360,7 +360,7 @@ class DecimalField(IntegerField):
if self.decimal_places is not None:
# Use exponential notation for small values since they might
# be parsed as 0 otherwise. ref #20765
step = str(Decimal('1') / 10 ** self.decimal_places).lower()
step = str(Decimal(1).scaleb(-self.decimal_places)).lower()
else:
step = 'any'
attrs.setdefault('step', step)