55 words
1 minute
Formatting thousands in Jinja
Anubhav Gain
2024-04-24

Formatting thousands in Jinja#

Here’s how to format a number in Jinja with commas for thousands, without needing any custom filters or template functions:

{{ "{:,}".format(row_count) }}

Output looks like this:

179,119

Bonus: here’s how to display a different pluralization of “row” if there is a single row:

{{ "{:,}".format(row_count) }} row{{ "" if row_count == 1 else "s" }}

Outputs:

179,119 rows
Formatting thousands in Jinja
https://mranv.pages.dev/posts/formatting-thousands-in-jinja/
Author
Anubhav Gain
Published at
2024-04-24
License
CC BY-NC-SA 4.0