I have the following code in my template:
{{ object.rating.get_percent|floatformat|add:"-100" }}
Which outputs -50
The value of object.rating.get_percent is 50. I want to subtract it from the number 100. So I am expecting 50 in return. Why do I get -50?
You get -50 because “-100” is the second operand to
add. The first operand is the result ofobject.rating.get_percent|floatformat.Essentially your expression is:
If you’re really desperate to calculate “100 – x”, you can use the
{% widthratio %}tag:However, you should really just get the backend developers to add a template filter for you.