如何“逗号”格式化django变量的输出?

时间:2023-01-14 10:41:08

I have this variable:

我有这个变量:

{{ object.article.rating.get_percent|floatformat }}

that outputs this:

输出这个:

540787

Is there a way to format it so it shows as:

有没有办法格式化它,因此它显示为:

540,787 

1 个解决方案

#1


12  

this should help you out: http://twigstechtips.blogspot.com/2010/02/django-formatting-numbers-with-commas.html

这应该可以帮到你:http://twigstechtips.blogspot.com/2010/02/django-formatting-numbers-with-commas.html

details: add "django.contrib.humanize" to your INSTALLED_APPS setting.

详细信息:将“django.contrib.humanize”添加到INSTALLED_APPS设置中。

then in the template:

然后在模板中:

{% load humanize %}
{{ price|intcomma }}

#1


12  

this should help you out: http://twigstechtips.blogspot.com/2010/02/django-formatting-numbers-with-commas.html

这应该可以帮到你:http://twigstechtips.blogspot.com/2010/02/django-formatting-numbers-with-commas.html

details: add "django.contrib.humanize" to your INSTALLED_APPS setting.

详细信息:将“django.contrib.humanize”添加到INSTALLED_APPS设置中。

then in the template:

然后在模板中:

{% load humanize %}
{{ price|intcomma }}