Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot round float to integer using jinja2

Tags:

python

jinja2

Have issues trying to get the jina2 template to perform a rounding. I don't really mind what happens, as all my numbers have been produced by multiplying a decimal less then 1 (e.g. 0.31) then multiplied by 100. So I have 31.0. I want to drop the decimal place, but nothing appears to work:

{{row.score.combined*100|float|round(0, 'floor')}}

or even the more easy:

{{row.score.combined*100|int}}

or even:

{{row.score.combined*100|round|int}}

I still get 31.0 in all cases.

like image 634
disruptive Avatar asked Aug 28 '17 19:08

disruptive


1 Answers

Requires brackets around the multiplication. Rounding was only occurring on the 100.

{{(row.score.combined*100)|int}}
like image 154
disruptive Avatar answered Oct 13 '22 01:10

disruptive