Opened 12 years ago
Closed 12 years ago
#18800 closed Bug (fixed)
Template cannot format integers bigger than maximum float
Reported by: | 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 |
Description
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)
Change History (6)
by , 12 years ago
Attachment: | local_history.patch added |
---|
comment:1 by , 12 years ago
Easy pickings: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
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 by , 12 years ago
Cc: | added |
---|
comment:3 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 12 years ago
Cc: | added |
---|---|
Needs tests: | unset |
Owner: | changed from | to
Patch needs improvement: | unset |
Status: | assigned → new |
Pull request with tests here: https://github.com/django/django/pull/358
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Remove float call that can break on big integers