Jinja Templates - Format a float as comma-separated currency

后端 未结 6 1723
轻奢々
轻奢々 2021-01-30 16:21

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

6条回答
  •  佛祖请我去吃肉
    2021-01-30 17:12

    Update: Using Jinja2 and Python 3, this worked quite nicely in the template without having to define any custom code:

    {{ "${:,.2f}".format(543921.9354) }}
    

    I'm not sure exactly what the dependencies are to have this work, but IMHO anyone else reading this answer would do well to at least try it before worrying about custom filters.

提交回复
热议问题