Is there any way that I can do some python math function in django template. Actually I need to round a variable value and I want to achieve this without using the filters.
For example like {{math.round(total)}}
.
Is there any way that I can do some python math function in django template. Actually I need to round a variable value and I want to achieve this without using the filters.
For example like {{math.round(total)}}
.
You can use floatformat to round of the value in django template.
{{ total|floatformat }}
If you want to perform more mathematical operations, you can try django-mathfilters. Or you could write your custom template tag and perform the operations in that template tag.
@arulmr gave the best way to fixed it, In my case I also needed include
{{ total|floatformat:0 }}
In order to round the value with zero decimal places, and
{{ total|floatformat:1 }}
To define the decimal places