Search code examples
jinja2

Converting string to integer without losing the decimals number(s)


I am trying to convert a string in to an integer in a Jinja template without losing the decimal numbers

I tried the following code which partially works;

{{myfield|int}}

The problem is that I loose any decimal numbers (5.5 becomes 5 for example) is there a way to fix this?


Solution

  • You can use float instead of int:

    {{myfield | float}}