#5748 closed (fixed)
Fix rounding issue with floatformat filter
Reported by: | Chris Beaven | Owned by: | Karen Tracey |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
#3004 introduced a precision argument for the floatformat
filter, but also discussed a rounding bug (it's a Python rounding problem with float
).
The best solution to these was using the decimal
module but the solution was not used because decimal
is a Python 2.4 feature. Since then, a port of the decimal
module has been included with Django.
So we can fix the rounding bug related with the floatformat
filter now.
Attachments (1)
Change History (9)
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 17 years ago
Has patch: | set |
---|
by , 17 years ago
Attachment: | 5478.django.template.defaultfilter.diff added |
---|
comment:4 by , 17 years ago
Owner: | changed from | to
---|
Good point there ;) Patch now includes the new floatformat using decimals and a test to show it works.
comment:5 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
It appears this bug is platform-dependent. The added test passes on current code on Windows (Pythons 2.3.5, 2.4.4, 2.5.2, 2.6b2), but fails on Linux (Pythons 2.4, 2.5). Patch as-is doesn't handle some cases correctly (non-ASCII input, NaN and Inf input on Windows prior to Python 2.6). I was going to add tests for these independent of checking in the fix for the rounding error, but some testing on Windows reveals NaN is not handled properly there with current code -- returned value not only doesn't match the string representation of NaN there, but differs from one Python level to another. Use of Decimal as in the patch helps to fix that, so I'm expanding the scope of this ticket to cover both, and will add tests for floatformat given non-ASCII, infinities, and NaN input.
comment:6 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I've attached an attempt at a patch, it passes all the regression tests for 'defaultfilters' - comments welcome!