1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #34363 -- Fixed floatformat crash on zero with trailing zeros.

Regression in 08c5a78726.
Follow up to 4b066bde69.
This commit is contained in:
Panagiotis H.M. Issaris
2023-02-22 20:46:16 +01:00
committed by GitHub
parent ad18a0102c
commit dcd9746983
2 changed files with 6 additions and 1 deletions

View File

@@ -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.