Jinja2 round filter not rounding Jinja2 round filter not rounding python python

Jinja2 round filter not rounding


You can put parens around the value that you want to round. (This works for division as well, contrary to what @sobri wrote.)

{{ (deet.value/100)|round }}

NOTE: round returns a float so if you really want the int you have to pass the value through that filter as well.

{{ (deet.value/100)|round|int }}


Didn't realize the filter operator had precedence over multiplication!

Following up on bernie's comment, I switched

{{ deet.value*100|round(1) }}

to

{{ 100*deet.value|round(1) }}

which solved the problem. I agree the processing should happen in the code elsewhere, and that would be better practice.


Try this

{{ (deet.value*100)|round(1) }}

If we didn't put parenthesis, round will do only to 100 not to the result.