---
title: Math
description: Calculate with numbers and format them for people
---

Calculate with numbers and format them for people.

## What it does

Math does one calculation and puts the answer in a field (`result` by default). The operations are:

* **Two numbers**: Add, Subtract, Multiply, Divide, Remainder, Power, Percentage of, Percentage change.
* **One number**: Round, Round down, Round up, Drop decimals, Absolute value, Negate, Square root.
* **A list**: Minimum, Maximum, Sum, Average.
* **Other**: Random number, and Format, which writes a number with separators, a currency or a percent sign.

Math is strict about input. Numbers and number-like text such as `"42"` are accepted. Empty text, a missing field, `null`, a list or `true`/`false` stop the run with a message, so a missing price never silently counts as zero. Dividing by zero also stops the run instead of returning infinity.

Round avoids the usual decimal trap: rounding `1.005` to 2 decimals gives `1.01`.

## When to use it

* Turn a scraped price like `"19.99"` into a number and do sums with it.
* Total or average a column of values, for example after [Aggregate](/nodes/builtin/datatransformation/aggregate/).
* Work out a discount or a price change as a percentage.
* Present a number for people: `1234.5` as `1,234.50 €` or `1 234,5`.

## Inputs and settings

* **Value**: usually an expression such as `{{ $input.price }}`. Left empty, Math uses the item's `value` field.
* **Percentage of** gives what share **Value** is of **Second Value** (`25` of `200` is `12.5`). **Percentage change** goes from **Value** to **Second Value** (`80` to `100` is `25`).
* **Values**: point it at a list, such as `{{ $input.price }}` after Aggregate.
* **Random number** picks between **Value** (default `0`) and **Second Value** (default `1`), both included.
* **Format As** *Percentage* multiplies by 100: `0.25` becomes `25%`. Leave **Locale** empty to follow the browser's language. An unknown locale or currency falls back to plain formatting.

## Outputs

The answer is in **Put Result In Field**, for example `{{ $input.result }}`. Format returns text; every other operation returns a number. With **Include Input Fields** on, the answer is added to the incoming item; off, the item holds only the answer. Minimum, Maximum, Sum and Average always return only the answer.

## Dependencies and credentials

None. This node needs no connection and has no slots for other nodes.

## Example workflow

1. [HTML Extract](/nodes/builtin/datatransformation/html-extract/) reads one item per product, each with a `price` field.
2. [Aggregate](/nodes/builtin/datatransformation/aggregate/) with **Mode** *Individual fields* collects every `price` into one list.
3. **Math** with **Operation** *Sum* and **Values** `{{ $input.price }}`.
4. A second **Math** with **Operation** *Format*, **Value** `{{ $input.result }}`, **Format As** *Currency*, **Currency** `EUR` and **Locale** `fr-FR` gives text such as `1 234,50 €`.

## Common issues

* **"The value is missing, not a number."** or **"The value is empty, so there is nothing to calculate with."** The field you pointed at does not exist or is blank on this item. Check the expression in **Value**, or remove the item first with [Filter](/nodes/builtin/flow/filter/).
* **"The value "19,99 €" is not a number."** Text with a currency sign or a decimal comma is not a number. Clean it first with [Regex](/nodes/builtin/datatransformation/regex/) or [Text / Formatter](/nodes/builtin/datatransformation/text-formatter/).
* **"Cannot divide by zero."** (also for Remainder, Percentage of and Percentage change from zero). The second number, or the starting number for a change, is `0`. Filter out those items first.
* **Sum or Average gives each item its own value instead of a total.** The numbers arrive as separate items. Collect them into one list with Aggregate and point **Values** at it.
* **Round down gives `-3` for `-2.5`.** Round down always goes lower. Use *Drop decimals* to get `-2`.

## Related nodes

* [Aggregate](/nodes/builtin/datatransformation/aggregate/): collect values into one list before Sum or Average.
* [Edit Fields](/nodes/builtin/datatransformation/editfields/): set fields with simple expressions.
* [Sort](/nodes/builtin/datatransformation/sort/): find the top or bottom items, not just the value.
* [Code](/nodes/builtin/core/code/): for calculations no operation covers.