简体   繁体   English

如何使用逗号打印数字作为Python / Django中的千位分隔符和小数位

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

I'm trying to display numbers in my Django templates with 我正试图在我的Django模板中显示数字

  1. commas as thousand sepaerator and 逗号为千分隔符和
  2. specifying the decimal places to round to. 指定要舍入的小数位数。

eg 76384.8739439 -> 76,384.87 例如76384.8739439 - > 76,384.87

Django has template tags to achieve both these. Django有模板标签来实现这两个目标。

  • intcomma - for thousand separator and intcomma - 千分隔符和
  • floatformat - for decimal places floatformat - 用于小数位

I can't seem to find a way to do both at the same time without writing my own custom template filter. 我似乎无法在不编写自己的自定义模板过滤器的情况下同时找到两种方法。 Anybody know of an easier solution? 有人知道更简单的解决方案吗?

{{ value|floatformat:2|intcomma }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM