开发者

How to print number with commas as thousands separator and decimal places in Python/Django

开发者 https://www.devze.com 2023-03-25 18:12 出处:网络
I\'m trying to display numbers in my Django templates with commas as thousand sepaerator and specifying the decimal places to round to.

I'm trying to display numbers in my Django templates with

  1. commas as thousand sepaerator and
  2. specifying the decimal places to round to.

e.g. 76384.8739439 -> 76,384.87

Django has template tags to achieve both these.

  • intcomma - for thousand separator and
  • floatformat - for decimal places

I can't seem to find a way to do both at the same time without writing m开发者_开发问答y own custom template filter. Anybody know of an easier solution?


{{ value|floatformat:2|intcomma }}
0

精彩评论

暂无评论...
验证码 换一张
取 消