Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "comma" format the output of a django variable?

Tags:

python

django

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 
like image 658
Tommy Avatar asked Jun 07 '11 19:06

Tommy


1 Answers

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

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

then in the template:

{% load humanize %}
{{ price|intcomma }}
like image 78
rolling stone Avatar answered Nov 08 '22 05:11

rolling stone