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

Created 2022-06-08T16:34:49-07:00, updated 2022-07-14T22:46:55-07:00 · History · Edit