Opened 6 years ago

Closed 6 years ago

#18800 closed Bug (fixed)

Template cannot format integers bigger than maximum float

Reported by: jbvsmo@… Owned by: nobody
Component: Template system Version: 1.4
Severity: Normal Keywords: float, long
Cc: jason@…, bradpitcher@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


I cannot render in templates any integer (long in this case) bigger than the maximum float (approx. 3e308) because the django.utils.numberformat module do cast everything to float just to check the sign.

Funny thing is that the number is then converted to string and the minus symbol is removed. So, the easiest fix would be: Grab the sign after string formatting.

I made this change and generated a patch with my IDE (that's why the funky file path). All the tests pass.

Attachments (1)

local_history.patch (716 bytes) - added by jbvsmo@… 6 years ago.
Remove float call that can break on big integers

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by jbvsmo@…

Attachment: local_history.patch added

Remove float call that can break on big integers

comment:1 Changed 6 years ago by Jason Mayfield

Easy pickings: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

I can confirm that passing in a number that's larger than sys.float_info.max does cause the django.utils.numberformat.format function to throw an exception. The patch needs to be updated with standard relative directory rather than the Windows-based directory that's on it now. Also needs a unit test.

comment:2 Changed 6 years ago by Jason Mayfield

Cc: jason@… added

comment:3 Changed 6 years ago by Brad Pitcher

Owner: changed from nobody to Brad Pitcher
Status: newassigned

comment:4 Changed 6 years ago by Brad Pitcher

Cc: bradpitcher@… added
Needs tests: unset
Owner: changed from Brad Pitcher to nobody
Patch needs improvement: unset
Status: assignednew

Pull request with tests here:

comment:5 Changed 6 years ago by Florian Apolloner <florian@…>

Resolution: fixed
Status: newclosed

In 319e1355190d414ee1b095b26fbb494cf9a27578:

Fixed #18800 -- Support numbers bigger than max float in numberformat.

Thanks to jbvsmo for the patch and Brad Pitcher for the tests.

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