I\'m trying to format a float as comma-separated currency. E.g. 543921.9354
becomes $543,921.94
. I\'m using the format
filter in Jinja t
Custom Filter using Babel (Can be used to format other currencies as well)
Install Babel (http://babel.pocoo.org/en/latest/api/numbers.html)
pip install Babel
Custom Jinja Filter
from babel.numbers import format_currency
@app.template_filter()
def usdollar(value):
return format_currency(value, 'USD', locale='en_US')
app.jinja_env.filters['usdollar'] = usdollar
Usage in Jinja Template:
{{ '-10000.500' | usdollar }}
Output : -$10,000.50