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 Sky Christensen, 5 years ago

Owner: changed from Sky Christensen to Sky Christensen

comment:2 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: assignedclosed
Summary: The floatformat filter sometimes returns "-0" instead of "0"The floatformat filter sometimes returns "-0" instead of "0".

I don't think it's an issue, this behavior is consistent with builtin round() and -0 exists in floating-point arithmetic.

You can start a discussion on the DevelopersMailingList if you believe that this behavior should be changed. We can re-open the ticket if we reach a consensus on a mailing list.

Last edited 5 years ago by Mariusz Felisiak (previous) (diff)

comment:3 by Sky Christensen, 5 years ago

Resolution: wontfix
Status: closednew

Re-opening following a discussion on the django-developers mailing list.

comment:4 by Sky Christensen, 5 years ago

Status: newassigned

comment:5 by Mariusz Felisiak, 5 years ago

Triage Stage: UnreviewedAccepted

comment:7 by Johannes Maron, 5 years ago

Patch needs improvement: set

comment:8 by Mariusz Felisiak, 5 years ago

Patch needs improvement: unset

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 3cf907c2:

Fixed #30761 -- Prevented floatformat filter from returning a negative zero.

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