Fixed #30761 -- Prevented floatformat filter from returning a negative zero.

This commit is contained in:
Sky 2019-10-31 13:05:26 +11:00 committed by Mariusz Felisiak
parent 459de8dc29
commit 3cf907c20c
4 changed files with 21 additions and 2 deletions

View file

@ -64,6 +64,16 @@ class FunctionTests(SimpleTestCase):
self.assertEqual(floatformat(0, 10), '0.0000000000')
self.assertEqual(floatformat(0.000000000000000000015, 20), '0.00000000000000000002')
def test_negative_zero_values(self):
tests = [
(-0.01, -1, '0.0'),
(-0.001, 2, '0.00'),
(-0.499, 0, '0'),
]
for num, decimal_places, expected in tests:
with self.subTest(num=num, decimal_places=decimal_places):
self.assertEqual(floatformat(num, decimal_places), expected)
def test_infinity(self):
pos_inf = float(1e30000)
neg_inf = float(-1e30000)