From bc1c03407649a37a8a3c26b8d0cb355ab2fc128e Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Sun, 23 Feb 2020 14:37:02 +0100 Subject: Fixed #28280 -- Prevented numberformat.format() from formatting large/tiny floats in scientific notation. --- django/utils/numberformat.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'django/utils') diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py index 961a60e37d..3bfdb2ea52 100644 --- a/django/utils/numberformat.py +++ b/django/utils/numberformat.py @@ -26,6 +26,9 @@ def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', return mark_safe(number) # sign sign = '' + # Treat potentially very large/small floats as Decimals. + if isinstance(number, float) and 'e' in str(number).lower(): + number = Decimal(str(number)) if isinstance(number, Decimal): if decimal_pos is not None: -- cgit v1.3