Opened 17 years ago

Closed 16 years ago

Last modified 8 years ago

#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)

5478.django.template.defaultfilter.diff (2.3 KB ) - added by Pete Crosier 17 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by Simon G <dev@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Pete Crosier, 17 years ago

Has patch: set

I've attached an attempt at a patch, it passes all the regression tests for 'defaultfilters' - comments welcome!

comment:3 by Chris Beaven, 17 years ago

PJ, wanna include some tests showing what this fixes? ;)

by Pete Crosier, 17 years ago

comment:4 by Pete Crosier, 17 years ago

Owner: changed from nobody to Pete Crosier

Good point there ;) Patch now includes the new floatformat using decimals and a test to show it works.

comment:5 by Karen Tracey, 16 years ago

Owner: changed from Pete Crosier to Karen Tracey
Status: newassigned

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 Karen Tracey, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [9369]) Fixed #5748 -- Made floatformat filter round properly on all platforms and handle NaN input correctly on Windows. Also added tests for these cases. Thanks for the report and initial patch to SmileyChris and PJCrosier.

comment:7 by Karen Tracey, 16 years ago

(In [9370]) [1.0.X] Fixed #5748 -- Made floatformat filter round properly on all platforms and handle NaN input correctly on Windows. Also added tests for these cases. Thanks for the report and initial patch to SmileyChris and PJCrosier.

[9369] from trunk.

comment:8 by GitHub <noreply@…>, 8 years ago

In 990ce638:

Refs #5748 -- Removed obsolete Python/Windows workarounds in floatformat filter.

Note: See TracTickets for help on using tickets.
Back to Top