Home > Software engineering >  How to format variable in template as currency?
How to format variable in template as currency?

Time:12-21

I am trying to format a string in a template to display as a currency. {{ object.cost }} Would I be able to do something like "${:,.2f}".format({{ object.cost }}) in the template?

CodePudding user response:

You can try to use floatformat filter:

{{ object.cost|floatformat:2 }}

where 2 means two decimals.

As, Django templates: output float with all decimal places

  • Related