Skip to content

Commit 794d6ce

Browse files
committed
Add filter to round numbers with commas as thousand separator
1 parent 6779402 commit 794d6ce

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

app.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,22 @@ def short_numeric_filter(
205205
) # print abbreviated output
206206

207207

208-
# add filter to Jinja
209-
app.jinja_env.filters["short_numeric"] = short_numeric_filter
208+
app.jinja_env.filters["short_numeric"] = (
209+
short_numeric_filter # add short numeric filter to Jinja
210+
)
211+
212+
213+
# round number with commas filter
214+
@app.template_filter("round_number_with_commas")
215+
def round_number_with_commas_filter(
216+
value: Union[int, float]
217+
) -> str: # round number with commas
218+
return f"{round(value):,}"
219+
220+
221+
app.jinja_env.filters["round_number_with_commas"] = (
222+
round_number_with_commas_filter # add round number with commas filter to Jinja
223+
)
210224

211225

212226
@app.route("/")

0 commit comments

Comments
 (0)