diff options
| author | Panagiotis H.M. Issaris <takis@issaris.com> | 2023-02-22 20:46:16 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-02-22 20:49:04 +0100 |
| commit | ce69dba0000be7686eabdffa9a8ff60296229109 (patch) | |
| tree | 0cc98217959f8da841d9b8cc0a65b96b804e50d3 /django | |
| parent | 48b2ba8a55c17d075c372f1e52d659bcb7e70aa5 (diff) | |
[4.2.x] Fixed #34363 -- Fixed floatformat crash on zero with trailing zeros.
Regression in 08c5a787262c1ae57f6517d4574b54a5fcaad124.
Follow up to 4b066bde692078b194709d517b27e55defae787c.
Backport of dcd974698301a38081c141ccba6dcafa5ed2c80e from main
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/defaultfilters.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 78881987fc..d446b54ade 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -3,7 +3,7 @@ import random as random_module import re import types import warnings -from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation +from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation, getcontext from functools import wraps from inspect import unwrap from operator import itemgetter @@ -184,6 +184,7 @@ def floatformat(text, arg=-1): units = len(tupl[1]) units += -tupl[2] if m else tupl[2] prec = abs(p) + units + 1 + prec = max(getcontext().prec, prec) # Avoid conversion to scientific notation by accessing `sign`, `digits`, # and `exponent` from Decimal.as_tuple() directly. |
