mirror of
https://github.com/django/django.git
synced 2024-12-27 03:25:58 +00:00
[4.2.x] Fixed #34363 -- Fixed floatformat crash on zero with trailing zeros.
Regression in08c5a78726
. Follow up to4b066bde69
. Backport ofdcd9746983
from main
This commit is contained in:
parent
48b2ba8a55
commit
ce69dba000
@ -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.
|
||||
|
@ -113,6 +113,10 @@ class FunctionTests(SimpleTestCase):
|
||||
)
|
||||
self.assertEqual(floatformat("0.00", 0), "0")
|
||||
self.assertEqual(floatformat(Decimal("0.00"), 0), "0")
|
||||
self.assertEqual(floatformat("0.0000", 2), "0.00")
|
||||
self.assertEqual(floatformat(Decimal("0.0000"), 2), "0.00")
|
||||
self.assertEqual(floatformat("0.000000", 4), "0.0000")
|
||||
self.assertEqual(floatformat(Decimal("0.000000"), 4), "0.0000")
|
||||
|
||||
def test_negative_zero_values(self):
|
||||
tests = [
|
||||
|
Loading…
Reference in New Issue
Block a user