Simplified and improved performance of floatformat filter.

Thanks Sergey Fedoseev for the review.
This commit is contained in:
Mariusz Felisiak 2017-12-19 16:08:10 +01:00 committed by Tim Graham
parent 770b9ea77f
commit 78247b80a8
1 changed files with 1 additions and 4 deletions

View File

@ -134,10 +134,7 @@ def floatformat(text, arg=-1):
if not m and p < 0:
return mark_safe(formats.number_format('%d' % (int(d)), 0))
if p == 0:
exp = Decimal(1)
else:
exp = Decimal('1.0') / (Decimal(10) ** abs(p))
exp = Decimal(1).scaleb(-abs(p))
# Set the precision high enough to avoid an exception (#15789).
tupl = d.as_tuple()
units = len(tupl[1])