83
If you donโt care about the commas, then floatformat
will do the job:
{{ value|floatformat:"0" }}
If you do care about commas, you want:
{{ value|floatformat:"0"|intcomma }}
(Hat tip to Stephen for pointing me at intcomma
!)
16
To use intcomma
filter, you should add django.contrib.humanize
to your INSTALLED_APPS
setting and {% load humanize %}
in a template.
- [Django]-Django check if object in ManyToMany field
- [Django]-Django auto_now and auto_now_add
- [Django]-Django โ Login with Email
4
You can do it with the below on django, the argument โ0โ rounds it to exclude decimal places, but you can change it.
number = 7715.625
rounded_number = round(number,0)
- [Django]-ImportError: Couldn't import Django
- [Django]-Django post_save preventing recursion without overriding model save()
- [Django]-Django using get_user_model vs settings.AUTH_USER_MODEL
0
You just need to use the round function and there is no need to specify the digits either. By default it returns an integer from the given float value.
number = 7715.615
rounded_number = round(number)
- [Django]-Automatically create an admin user when running Django's ./manage.py syncdb
- [Django]-Django โ Overriding the Model.create() method?
- [Django]-How to specify the login_required redirect url in django?
Source:stackexchange.com