Opened 5 years ago
Closed 5 years ago
#30761 closed Bug (fixed)
The floatformat filter sometimes returns "-0" instead of "0".
Reported by: | Sky Christensen | Owned by: | Sky Christensen |
---|---|---|---|
Component: | Template system | Version: | 2.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
For values between 0 and -0.5, the floatformat filter returns "-0" where I would expect it to return "0".
For example:
$ python -m django --version 2.2.5 $ ./manage.py shell Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django.template.defaultfilters import floatformat >>> floatformat(-0.1, 0) '-0' >>> floatformat(-0.01, 1) '-0.0' >>> floatformat(-0.001, 2) '-0.00' >>> floatformat(-0.4, 0) '-0'
If others agree that this is a bug, I'll submit a patch.
Change History (9)
comment:1 by , 5 years ago
Owner: | changed from | to
---|
comment:2 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Summary: | The floatformat filter sometimes returns "-0" instead of "0" → The floatformat filter sometimes returns "-0" instead of "0". |
Version 0, edited 5 years ago by (next)
comment:3 by , 5 years ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
Re-opening following a discussion on the django-developers mailing list.
comment:4 by , 5 years ago
Status: | new → assigned |
---|
comment:5 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:7 by , 5 years ago
Patch needs improvement: | set |
---|
Note:
See TracTickets
for help on using tickets.
I don't think it's an issue, this behavior is consistent with builtin
round()
and-0
exists in floating-point arithmetic.