diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-01-03 13:09:12 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-01-03 13:09:12 +0000 |
| commit | e5719b203c5a1ee799cd8cb6100342940e260fd7 (patch) | |
| tree | 65db62e256ff03cbabb73a6ec87e9c17eae9aaa0 | |
| parent | c93933441e77cefbcb354196bda9a29b7e75df18 (diff) | |
Fixed #17496 -- Regression in the floatformat template filter, introduced by the fix for #15789.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17335 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/template/defaultfilters.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/defaultfilters/tests.py | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 4530adf7c5..9eabb6dd60 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -169,7 +169,7 @@ def floatformat(text, arg=-1): # Set the precision high enough to avoid an exception, see #15789. tupl = d.as_tuple() units = len(tupl[1]) - tupl[2] - prec = abs(arg) + units + 1 + prec = abs(p) + units + 1 # Avoid conversion to scientific notation by accessing `sign`, `digits` # and `exponent` from `Decimal.as_tuple()` directly. diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index 5288e50177..5e8c8f1538 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -69,6 +69,8 @@ class DefaultFiltersTests(TestCase): try: self.assertEqual(floatformat(1.2345, 2), u'1.23') self.assertEqual(floatformat(15.2042, -3), u'15.204') + self.assertEqual(floatformat(1.2345, '2'), u'1.23') + self.assertEqual(floatformat(15.2042, '-3'), u'15.204') self.assertEqual(floatformat(decimal.Decimal('1.2345'), 2), u'1.23') self.assertEqual(floatformat(decimal.Decimal('15.2042'), -3), u'15.204') finally: |
