Cannot round float to integer using jinja2

2020-07-13 09:29发布

问题:

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.

回答1:

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

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


标签: python jinja2