Overview
The "Number Calculator" node performs simple mathematical operations on numeric fields within incoming data items. It supports addition, subtraction, multiplication, division, and squaring of numbers. This node is useful when you need to automate basic arithmetic calculations as part of a workflow, such as computing totals, differences, ratios, or powers based on dynamic input data.
For example, you can use it to:
- Calculate the ratio of two values by dividing one field by another.
- Compute the square of a measurement for further analysis.
- Add or subtract quantities from different fields in your dataset.
Properties
| Name | Meaning |
|---|---|
| First Number Field | The name of the field containing the first number to be used in the operation. |
| Second Number Field | The name of the field containing the second number (not required for the square operation). Options: any string representing a field name. |
| Output Field | The name of the field where the result of the operation will be stored. |
Output
The node outputs an array of items where each item contains the original JSON data plus a new field (as specified by the "Output Field" property) holding the result of the calculation.
Example output structure for an item:
{
"json": {
"number1": 10,
"number2": 5,
"result": 2
}
}
If an error occurs during processing of an item (e.g., invalid number or division by zero), and if the node is configured to continue on failure, the output item will include an error field describing the issue.
This node does not output binary data.
Dependencies
- No external services or API keys are required.
- The node relies solely on the input data provided to it.
- No special environment variables or n8n configurations are necessary.
Troubleshooting
- Invalid Number Fields: If the specified "First Number Field" or "Second Number Field" does not contain a valid number, the node will throw an error indicating which field is invalid. Ensure that these fields exist and contain numeric values.
- Division by Zero: When performing division, if the second number is zero, the node throws an error stating that division by zero is not allowed. Validate input data to avoid zero denominators.
- Unknown Operation: If an unsupported operation is selected, the node will throw an error about the unknown operation. Use only the supported operations: add, subtract, multiply, divide, square.
- Continue On Fail: If enabled, the node will continue processing subsequent items even if some items cause errors, including error details in the output.