knoten / builtin / datatransformation
Math
Calculate with numbers and format them for people
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Calculate with numbers and format them for people.
What it does
Section titled “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
Section titled “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.
- Work out a discount or a price change as a percentage.
- Present a number for people:
1234.5as1,234.50 €or1 234,5.
Inputs and settings
Section titled “Inputs and settings”| Einstellung | Typ | Was es bewirkt |
|---|---|---|
| Operation | Choice | The calculation to perform. 21 options. Standard: Add |
| Value | Value | The number to work on. |
| Second Value | Value | The second number, for Add, Subtract, Percentage and the rest. |
| Values | Value | The list of numbers, for Minimum, Maximum, Sum and Average. |
| Decimal Places | Number | How many decimal places Round keeps. Standard: 0 |
| Format As | Choice | How Format presents the number. Options: Plain number, Currency, Percentage. Standard: Plain number |
| Locale | Text | Language tag deciding separators, such as en-US or fr-FR. |
| Currency | Text | Three-letter currency code, used when formatting as currency. Standard: USD |
| Minimum Decimals | Number | Fewest decimal places Format shows. Standard: 0 |
| Maximum Decimals | Number | Most decimal places Format shows. Standard: 2 |
| Whole Number | Toggle | Whether Random returns a whole number. Standard: On |
| Put Result In Field | Text | Name of the field holding the answer. Standard: result |
| Include Input Fields | Toggle | Keep the incoming item’s fields alongside the answer. Standard: On |
- Value: usually an expression such as
{{ $input.price }}. Left empty, Math uses the item’svaluefield. - Percentage of gives what share Value is of Second Value (
25of200is12.5). Percentage change goes from Value to Second Value (80to100is25). - Values: point it at a list, such as
{{ $input.price }}after Aggregate. - Random number picks between Value (default
0) and Second Value (default1), both included. - Format As Percentage multiplies by 100:
0.25becomes25%. Leave Locale empty to follow the browser’s language. An unknown locale or currency falls back to plain formatting.
Outputs
Section titled “Outputs”-
Output
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
Section titled “Dependencies and credentials”None. This node needs no connection and has no slots for other nodes.
Example workflow
Section titled “Example workflow”- HTML Extract reads one item per product, each with a
pricefield. - Aggregate with Mode Individual fields collects every
priceinto one list. - Math with Operation Sum and Values
{{ $input.price }}. - A second Math with Operation Format, Value
{{ $input.result }}, Format As Currency, CurrencyEURand Localefr-FRgives text such as1 234,50 €.
Common issues
Section titled “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.
- “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 or 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
-3for-2.5. Round down always goes lower. Use Drop decimals to get-2.
Related nodes
Section titled “Related nodes”- Aggregate: collect values into one list before Sum or Average.
- Edit Fields: set fields with simple expressions.
- Sort: find the top or bottom items, not just the value.
- Code: for calculations no operation covers.