# django-mathfilters

{% load mathfilters %} ...## Basic math filters

- 8 + 3 = {{ 8|add:3 }}
- 13 - 17 = {{ 13|sub:17 }} {% with answer=42 %}
- 42 * 0.5 = {{ answer|mul:0.5 }} {% endwith %} {% with numerator=12 denominator=3 %}
- 12 / 3 = {{ numerator|div:denominator }} {% endwith %}
- |-13| = {{ -13|abs }}

**Here is what the above code is Doing:**

1. The first line loads the mathfilters module.

2. The second line uses the add filter to add 8 and 3.

3. The third line uses the sub filter to subtract 17 from 13.

4. The fourth line uses the mul filter to multiply 42 by 0.5.

5. The fifth line uses the div filter to divide 12 by 3.

6. The sixth line uses the abs filter to get the absolute value of -13.

Here’s what the output looks like:

Basic math filters

8 + 3 = 11

13 – 17 = -4

42 * 0.5 = 21.0

12 / 3 = 4.0

|-13| = 13