Registry / data / node-red-contrib-calc

node-red-contrib-calc

JSON →
library1.0.6jsnpmunverified

node-red-contrib-calc is a Node-RED node designed to perform a range of basic mathematical operations directly within Node-RED flows. Currently at version 1.0.6, it primarily receives maintenance updates, with recent releases focusing on expanding available operations like `truncate` and enhancing result formatting. Unlike traditional JavaScript libraries, this package integrates as a graphical node in the Node-RED editor. Its core differentiator lies in providing a simplified, visual interface for common arithmetic, aggregation (min, max, average), and rounding tasks, allowing users to easily inject, process, and output numerical data within their IoT and automation workflows without writing custom functions. It is positioned as a simpler alternative to more advanced statistical packages like `node-red-contrib-statistics`.

npm install node-red-contrib-calc
INSTALL
IMPORT
SIG · NODE-RED-CONTRIB-C
N
node-red-contrib-calc
datajavascriptv1.0.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

This example Node-RED flow demonstrates how to configure the `calc` node to find the maximum value from an array of numbers injected into the flow, and then display the result in the Node-RED debug sidebar.

[ { "id": "b6bc5399.8385e", "type": "calculator", "z": "4142483e.06fca8", "name": "", "inputMsgField": "payload", "outputMsgField": "payload", "operation": "max", "constant": "", "round": false, "decimals": 0, "x": 640, "y": 3060, "wires": [ ["4c297cba.7585a4"] ] }, { "id": "e5a3b930.003428", "type": "inject", "z": "4142483e.06fca8", "name": "", "topic": "", "payload": "[321,123,333,222,111]", "payloadType": "json", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "showConfirmation": false, "confirmationLabel": "", "x": 420, "y": 3060, "wires": [ ["b6bc5399.8385e"] ] }, { "id": "4c297cba.7585a4", "type": "debug", "z": "4142483e.06fca8", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 830, "y": 3060, "wires": [] } ]
Debug
Known issues
gotchaThe input data structure (single number, array of numbers, or fixed-length array) required by the node depends on the specific mathematical operation selected. Supplying incorrect data types or structures can lead to errors.
fix
Consult the node's configuration sidebar or documentation to understand the exact input requirements for the chosen operation. Use debug nodes upstream to verify input message content and type.
affects: >=1.0.0
gotchaThis node is designed for basic mathematical calculations and aggregations. For advanced statistical analysis, complex data transformations, or machine learning capabilities, it is generally insufficient.
fix
For advanced statistical analysis or more complex mathematical transformations, consider using `node-red-contrib-statistics` or implementing custom JavaScript functions within a Node-RED `function` node.
affects: >=1.0.0
gotchaThe `round` and `truncate` options for decimal places behave differently. `Round` performs standard mathematical rounding (e.g., 2.5 rounds to 3), while `truncate` simply cuts off decimal places (e.g., 2.9 truncates to 2) without rounding up.
fix
Carefully select between `round` and `truncate` based on the desired numerical precision behavior. Test with edge cases to ensure the output matches expectations.
affects: >=1.0.6
Errors
Common errors & fixes
Error: Input for operation 'Multiply' must be an array of at least 2 numbers.
An operation requiring an array of multiple numbers (e.g., 'Multiply', 'Average') received a single number or an array with too few elements.
fix
Ensure the input message field (e.g., `msg.payload`) contains an array with the minimum required number of elements for the selected operation, for example, `[2, 3]` for multiplication.
TypeError: Cannot read properties of undefined (reading 'length')
The configured input message field (e.g., `msg.payload`) is either undefined, null, or does not contain a valid number or an array of numbers, preventing the node from processing.
fix
Verify that the input message field, as configured in the node's properties, correctly points to a numeric value or an array of numbers. Use an upstream debug node to inspect `msg` content.
Output displays 'NaN' (Not a Number) in debug sidebar.
An operation was performed on non-numeric input data, or a mathematical operation resulted in an undefined outcome (e.g., division by zero, or an operation on `Infinity`).
fix
Check upstream nodes to ensure only valid numeric inputs are being sent to the `calc` node. Use debug nodes to inspect the input `msg.payload` or the chosen input field before it reaches the calculator node.
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-red-contrib-calc — npm install node-red-contrib-calc · libregistry