Ticket #17496: floatformat.diff

File floatformat.diff, 1.3 KB (added by Florian Apolloner, 13 years ago)
  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index 4530adf..9eabb6d 100644
    a b def floatformat(text, arg=-1):  
    169169        # Set the precision high enough to avoid an exception, see #15789.
    170170        tupl = d.as_tuple()
    171171        units = len(tupl[1]) - tupl[2]
    172         prec = abs(arg) + units + 1
     172        prec = abs(p) + units + 1
    173173
    174174        # Avoid conversion to scientific notation by accessing `sign`, `digits`
    175175        # and `exponent` from `Decimal.as_tuple()` directly.
  • tests/regressiontests/defaultfilters/tests.py

    diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
    index 5288e50..5e8c8f1 100644
    a b class DefaultFiltersTests(TestCase):  
    6969        try:
    7070            self.assertEqual(floatformat(1.2345, 2), u'1.23')
    7171            self.assertEqual(floatformat(15.2042, -3), u'15.204')
     72            self.assertEqual(floatformat(1.2345, '2'), u'1.23')
     73            self.assertEqual(floatformat(15.2042, '-3'), u'15.204')
    7274            self.assertEqual(floatformat(decimal.Decimal('1.2345'), 2), u'1.23')
    7375            self.assertEqual(floatformat(decimal.Decimal('15.2042'), -3), u'15.204')
    7476        finally:
Back to Top