Overview
This node, named "Number Calculator," performs simple mathematical operations on numeric fields within incoming data items. It supports addition, subtraction, multiplication, division, and squaring of numbers. The node is useful in scenarios where you need to compute new values based on existing numeric fields in your workflow data, such as calculating totals, differences, products, ratios, or squares for further processing or reporting.
For example:
- Multiplying two fields representing quantity and price to get a total cost.
- Squaring a measurement value to calculate area.
- Dividing one metric by another to find a ratio.
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 to be used (not required for square). |
| Output Field | The name of the field where the result of the operation will be stored. |
The supported operations are:
- Add
- Subtract
- Multiply
- Divide
- Square (only uses the first number field)
Output
The output consists of the original input JSON data extended with a new field (as specified by the "Output Field" property) containing the result of the mathematical operation.
Example output JSON structure for an item might look like:
{
"number1": 5,
"number2": 3,
"result": 15
}
(where result holds the product of number1 and number2 if the multiply operation was selected).
If an error occurs during processing of an item and the node is configured to continue on failure, the output for that item will include an error field describing the issue.
Dependencies
- No external services or API keys are required.
- This node relies solely on the input data provided to it.
- No special environment variables or n8n configurations are needed.
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.
- Division by Zero: Attempting to divide by zero will cause an error.
- Unknown Operation: If an unsupported operation is selected, an error will be thrown.
- To handle errors gracefully, enable the "Continue On Fail" option in the node settings to allow processing of subsequent items even if some fail.