Search code examples
djangonumbersroundingdecimal

Rounding off decimals in Django


I want to round off my decimal values as below:

7,715.625 becomes 7,716

How do I achieve this?


Solution

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