Jinja Templates - Format a float as comma-separated currency

后端 未结 6 1794
轻奢々
轻奢々 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:13

    Write a custom filter for that. If you are using python 2.7, it can look like this:

    def format_currency(value):
        return "${:,.2f}".format(value)
    

提交回复
热议问题