views:

484

answers:

2

I want to round off my decimal values as below:

7,715.625 becomes 7,716

How do I achieve this?

+2  A: 

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!)

Dominic Rodger
floatformat will give me one decimal place...I tried this first. I need to have my value without any decimal place
@Stephen - See my edit.
Dominic Rodger
sweet...didn't know about the floatformat:"0". thanks
@Dominic {{ value|floatformat:"0"|intcomma }} will add the thousands separator (it's part of humanize)
@Stephen - thanks - I was actually looking for that exact filter today, and couldn't find it. Much appreciated.
Dominic Rodger
A: 

To use 'intcomma' filter, you should add 'django.contrib.humanize' to your INSTALLED_APPS setting and {% load humanize %} in a template.

Sjoo