{"id":14740,"library":"node-red-contrib-calc","title":"Node-RED Calculator Node","description":"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`.","status":"active","version":"1.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/bartbutenaers/node-red-contrib-calc","tags":["javascript","node-red","math","mathematics","calculate","min","max","round","trunc"],"install":[{"cmd":"npm install node-red-contrib-calc","lang":"bash","label":"npm"},{"cmd":"yarn add node-red-contrib-calc","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-red-contrib-calc","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[],"quickstart":{"code":"[\n  {\n    \"id\": \"b6bc5399.8385e\",\n    \"type\": \"calculator\",\n    \"z\": \"4142483e.06fca8\",\n    \"name\": \"\",\n    \"inputMsgField\": \"payload\",\n    \"outputMsgField\": \"payload\",\n    \"operation\": \"max\",\n    \"constant\": \"\",\n    \"round\": false,\n    \"decimals\": 0,\n    \"x\": 640,\n    \"y\": 3060,\n    \"wires\": [\n      [\"4c297cba.7585a4\"]\n    ]\n  },\n  {\n    \"id\": \"e5a3b930.003428\",\n    \"type\": \"inject\",\n    \"z\": \"4142483e.06fca8\",\n    \"name\": \"\",\n    \"topic\": \"\",\n    \"payload\": \"[321,123,333,222,111]\",\n    \"payloadType\": \"json\",\n    \"repeat\": \"\",\n    \"crontab\": \"\",\n    \"once\": false,\n    \"onceDelay\": 0.1,\n    \"showConfirmation\": false,\n    \"confirmationLabel\": \"\",\n    \"x\": 420,\n    \"y\": 3060,\n    \"wires\": [\n      [\"b6bc5399.8385e\"]\n    ]\n  },\n  {\n    \"id\": \"4c297cba.7585a4\",\n    \"type\": \"debug\",\n    \"z\": \"4142483e.06fca8\",\n    \"name\": \"\",\n    \"active\": true,\n    \"tosidebar\": true,\n    \"console\": false,\n    \"tostatus\": false,\n    \"complete\": \"false\",\n    \"x\": 830,\n    \"y\": 3060,\n    \"wires\": []\n  }\n]","lang":"json","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"This node is designed for basic mathematical calculations and aggregations. For advanced statistical analysis, complex data transformations, or machine learning capabilities, it is generally insufficient.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Carefully select between `round` and `truncate` based on the desired numerical precision behavior. Test with edge cases to ensure the output matches expectations.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.6"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"An operation requiring an array of multiple numbers (e.g., 'Multiply', 'Average') received a single number or an array with too few elements.","error":"Error: Input for operation 'Multiply' must be an array of at least 2 numbers."},{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'length')"},{"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.","cause":"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`).","error":"Output displays 'NaN' (Not a Number) in debug sidebar."}],"ecosystem":"npm"}