Reputation: 4502
I'm having trouble formatting a list of values in Jinja.
Current List:
[0, 0.2608695652173913, 0]
Needed List:
[0, 26.08, 0]
Code:
[{{ record['result']|map(attribute='record')|join(', ') }}]
What is the correct syntax to apply the format
filter with something like {0:0.2f}
?
Upvotes: 1
Views: 1906
Reputation: 4608
You can do something like this...
def FormatDecimal(value):
return "{0:0.2f}".format(float(value))
jinja2.filters.FILTERS['FormatDecimal'] = FormatDecimal
Then use this in your template...
{{ SomeValue | FormatDecimal }}
Hope this helps!
Upvotes: 2