The floatformat filter sometimes returns "-0" rather than "0"

131 views
Skip to first unread message

Sky Christensen

unread,
Sep 12, 2019, 7:27:14 AM9/12/19
to django-d...@googlegroups.com
Hi,

I'd like to discuss reopening this wontfix'ed ticket:
https://code.djangoproject.com/ticket/30761

The issue is that for values between 0 and -0.5, the floatformat filter
returns "-0", whereas I think that most people would expect it to return
"0".

The ticket was wontfix'ed because "this behavior is consistent with
builtin round() and -0 exists in floating-point arithmetic".

Can I propose that in this case the better way to decide the result that
it should produce is to ask what an ordinary person would expect to see,
rather than what's consistent with a particular Python function?

When humans round -0.3 to the nearest whole number, we express the
result as 0, not -0. Given that the point of template tags and filters
is to make data more human-readable, I think returning "0" is preferable
in this case than returning "-0".

If this ticket is reopened, I'll be happy to submit a patch for it.

Cheers,

Sky

Kye Russell

unread,
Sep 12, 2019, 7:46:16 AM9/12/19
to django-d...@googlegroups.com
Sounds reasonable. As you said, the template tags (well, this one) seem to be to prepare things for human consumption, not to expose computer science intricacies.

If I saw this presented on a website, as a ‘developer-user’, I’d probably consider it a bug. I’m unsure of other uses of this filter though.

Kye Russell
Sent from my iPhone
> --
> You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/aec9450abcb511a0bb4a020c770a0483%40skychristensen.com.

Adam Johnson

unread,
Sep 12, 2019, 7:53:22 AM9/12/19
to django-d...@googlegroups.com
+1 to swapping -0 for 0



--
Adam

Sky Christensen

unread,
Sep 25, 2019, 7:55:46 PM9/25/19
to django-d...@googlegroups.com
It seems that so far two people have replied in favour of re-opening
this ticket (or maybe make that three people if you count me), and none
have replied against re-opening it.

It's been two weeks since the last reply.

What's the next step now?
> https://groups.google.com/d/msgid/django-developers/CAMyDDM3FhTEUmWmpHaAqHuRxCbqHJcH6riS9vQ%2BNjhx3LcGhPA%40mail.gmail.com
> [1].
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/django-developers/CAMyDDM3FhTEUmWmpHaAqHuRxCbqHJcH6riS9vQ%2BNjhx3LcGhPA%40mail.gmail.com?utm_medium=email&utm_source=footer

Adam Johnson

unread,
Sep 26, 2019, 6:59:15 AM9/26/19
to django-d...@googlegroups.com
I think you can reopen the ticket and make a pull request!



--
Adam

Sky Christensen

unread,
Sep 26, 2019, 11:25:55 PM9/26/19
to django-d...@googlegroups.com
Thanks Adam. I wasn't sure if I needed to wait for a core developer to
re-open the ticket.

I just re-opened it then and I'll get onto writing a patch soon.
> https://groups.google.com/d/msgid/django-developers/CAMyDDM2jQXp3FDjmiHzYoxWM069%3D6royttHd6Av8a4GUT%3DpYmA%40mail.gmail.com
> [1].
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/django-developers/CAMyDDM2jQXp3FDjmiHzYoxWM069%3D6royttHd6Av8a4GUT%3DpYmA%40mail.gmail.com?utm_medium=email&utm_source=footer
Reply all
Reply to author
Forward
0 new messages