[Django] #32955: widthratio does not round properly

10 views
Skip to first unread message

Django

unread,
Jul 21, 2021, 6:20:00 AM7/21/21
to django-...@googlegroups.com
#32955: widthratio does not round properly
-------------------------------------------+------------------------
Reporter: alfonsrv | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------------+------------------------
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 #}
}}}


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

--
Ticket URL: <https://code.djangoproject.com/ticket/32955>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 21, 2021, 6:23:54 AM7/21/21
to django-...@googlegroups.com
#32955: widthratio does not round properly
---------------------------------+--------------------------------------

Reporter: alfonsrv | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by alfonsrv:

Old description:

> 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 #}
> }}}
>

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

New description:

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32955#comment:1>

Django

unread,
Jul 21, 2021, 6:36:04 AM7/21/21
to django-...@googlegroups.com
#32955: widthratio does not round properly
---------------------------------+--------------------------------------
Reporter: alfonsrv | Owner: nobody
Type: Bug | Status: closed

Component: Template system | Version: 3.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* type: Uncategorized => Bug
* resolution: => invalid
* easy: 1 => 0


Comment:

`widthratio` uses built-in `round()` on floats so it's not really a bug,
see [https://docs.python.org/3/library/functions.html#round a note in
round()'s docs].

--
Ticket URL: <https://code.djangoproject.com/ticket/32955#comment:2>

Reply all
Reply to author
Forward
0 new messages