1
0
mirror of https://github.com/django/django.git synced 2024-12-27 19:46:22 +00:00

[4.2.x] Fixed #34272 -- Fixed floatformat crash on zero with trailing zeros to zero decimal places.

Regression in 08c5a78726.

Thanks Andrii Lahuta for the report.

Backport of 4b066bde69 from main
This commit is contained in:
David Wobrock 2023-01-18 22:54:17 +01:00 committed by Mariusz Felisiak
parent a3771c8229
commit 3b6f307344
2 changed files with 3 additions and 1 deletions

View File

@ -168,7 +168,7 @@ def floatformat(text, arg=-1):
except (ValueError, OverflowError, InvalidOperation):
return input_val
if not m and p < 0:
if not m and p <= 0:
return mark_safe(
formats.number_format(
"%d" % (int(d)),

View File

@ -111,6 +111,8 @@ class FunctionTests(SimpleTestCase):
self.assertEqual(
floatformat(0.000000000000000000015, 20), "0.00000000000000000002"
)
self.assertEqual(floatformat("0.00", 0), "0")
self.assertEqual(floatformat(Decimal("0.00"), 0), "0")
def test_negative_zero_values(self):
tests = [