From 78247b80a8cbf1ebfb7a54624de7dc92e1a1f888 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 19 Dec 2017 16:08:10 +0100 Subject: [PATCH] Simplified and improved performance of floatformat filter. Thanks Sergey Fedoseev for the review. --- django/template/defaultfilters.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index c5f520bc33..5d7665d64e 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -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])