# Calculations

> Let a template do the math on the numbers you enter, like hours times rate.

Calculations are Smart Fields that do the math on numbers you enter, like hours times rate, so a rich snippet works out a total for you. Add them in the [rich text editor](https://simplefill.app/docs/rich-text-editor) with `{{`.

## The four calculations

They’re under **Insert field** > **Calculations**:

| Calculation | What it does |
| --- | --- |
| **Add Fields** | Adds two or more fields together |
| **Subtract Fields** | Takes each following field away from the first |
| **Multiply Fields** | Multiplies two or more fields |
| **Divide Fields** | Divides the first field by each following field |

## Build an invoice line

1. In a rich snippet, add two Text fields: `hours` and `rate`. Use **Insert field** > **Basic Fields** > **Text**, or saved [Fields](https://simplefill.app/docs/fields).
2. Type `{{` and choose **Multiply Fields**.
3. Click the new pill. Under **Fields to calculate**, select `hours` and `rate`.
4. Click **Save changes**.

```
Design work: {{hours}} hours at ${{rate}}/hour = ${{multiply}}
```

When you insert it, enter `12.5` and `80`, and the snippet says `= $1000`.

## Tips

- A calculation needs at least two fields in the same snippet. It can also use the result of another calculation, so a subtotal can feed a total.
- Fields are calculated in the order you select them, which matters for Subtract and Divide.
- The math is exact to 12 decimal places. Add a `round` [Transform](https://simplefill.app/docs/transforms#numbers) to tidy the result.
- Numbers are read using the **Number format** in [Settings](https://simplefill.app/docs/settings). With `1.234,56`, type `12,5` for twelve and a half.
- A calculation can’t depend on itself. SimpleFill stops you if a chain would loop.

## Where they work

Calculations work inside rich snippets and [Blocks](https://simplefill.app/docs/blocks) only. Typing `;multiply` on a page does nothing, because there’s nothing to calculate there.

To show different text depending on a number, use a [condition](https://simplefill.app/docs/conditions).

Source: https://simplefill.app/docs/calculations
