Reputation: 35
I have some float values that represent percentages, but they have too many decimal places. How can I display a shorter value in my Jinja template?
{% for item in items %}
{{ item.name }}
{{ item.score }}%
{% endfor %}
person
10.2419833200485471%
I'd like to display "10.24%" instead.
Upvotes: 0
Views: 402
Reputation: 9440
You can use the round filter. The documentation shows some ways you can control the rounding.
{{ item.score|round(2) }}
Upvotes: 1