Opened 3 years ago

Closed 3 years ago

#32955 closed Bug (invalid)

widthratio does not round properly

Reported by: alfonsrv Owned by: nobody
Component: Template system Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by alfonsrv)

The documentation states, quote

175/200 = .875; .875 * 100 = 87.5 which is rounded up to 88

Using the example provided in the official documentation produces 88px. However when dividing 5/2, it results in 2 instead of what I would expect to be 3.

{% widthratio 5 2 1 as width %}
The width is: {{ width }} {# results in 2 instead of 3 #}

When using 7 instead of 5, the width results in the expected 4.

https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#:~:text=87.5%20which%20is%20rounded%20up%20to%2088

Change History (2)

comment:1 by alfonsrv, 3 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 3 years ago

Easy pickings: unset
Resolution: invalid
Status: newclosed
Type: UncategorizedBug

widthratio uses built-in round() on floats so it's not really a bug, see a note in round()'s docs.

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