Opened 14 years ago
Closed 14 years ago
#17779 closed Bug (invalid)
floatformat template filter no longer works at all
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Release blocker | Keywords: | floatformat templatetag |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
As of a recent commit, the floatformat template filter no longer works at all:
>>> from django.template.defaultfilters import floatformat
>>> import decimal
>>> floatformat(decimal.Decimal('12.345'), 2)
u'12.345'
>>> floatformat(12.345, 2)
u'12.345'
>>> floatformat(12.345, 5)
u'12.345'
>>> floatformat(12.345, -2)
u'12.345'
Change History (2)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
I traced the problem to a build of Python that was incapable of doing proper math with the Decimal class; the bug is not in Django. Apologies for the noise.
Note:
See TracTickets
for help on using tickets.
The input value is simply returned due to this exception occurring when floatformat tries to quantize the Decimal instance:
Traceback (most recent call last): File "<console>", line 1, in <module> File "/Users/.../django/template/defaultfilters.py", line 177, in floatformat Context(prec=prec)).as_tuple() File "/usr/local/Cellar/python/2.7.2/lib/python2.7/decimal.py", line 2442, in quantize 'quantize result has too many digits for current context') File "/usr/local/Cellar/python/2.7.2/lib/python2.7/decimal.py", line 3844, in _raise_error raise error(explanation) InvalidOperation: quantize result has too many digits for current contextThis exception is caught at the end of the floatformat function and input_val is returned.