# Announce node-red-contrib-math

**URL:** https://discourse.nodered.org/t/announce-node-red-contrib-math/5100
**Category:** Share Your Nodes
**Created:** [21 November 2018 20:09 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100 "2018-11-21T20:09:06Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [21 November 2018 20:09 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/1 "2018-11-21T20:09:06Z")

</div>

Hi folks,

I needed this week some very basic mathematic stuff, but I didn't want to create a function node for it. So I tried to find something on [flows.nodered.org](http://flows.nodered.org), however without success...

I'm pretty sure there must something exist already, but I gave up searching after some time and started creating my own [node-red-contrib-math](https://github.com/bartbutenaers/node-red-contrib-math) node. So if somebody now offers me a link to an existing node with similar functionality, I will most probably drop dead instantaneously 🤔

It allows you to do rounding, truncating, summing, subtracting, multiplying, finding maximums, finding minimums, ... It can do that on a single number, but also on all numbers in an array.

As usual, all 'constructive' feedback is more than welcome before I publish it on npm. You can install the current version directly from Github:

```auto
npm install bartbutenaers/node-red-contrib-math

```

Thanks !  
Bart

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [21 November 2018 20:29 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/2 "2018-11-21T20:29:14Z")

</div>

What does it output if you ask for 6 times 9?

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [21 November 2018 20:58 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/3 "2018-11-21T20:58:09Z")

</div>

Hi Simon,

I assume this is some kind of catch-question, but I'm not sure which direction you go ...

This is 6 times 9 using the math-node:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7302729a3547e1ba5dec9195f9a7702fedbff312.png)

Have asked my 3 year old son, I he agrees that this should be the correct result.  
Did you have anything else in mind ? Perhaps `"54"` for the string-lovers among us?

Bart

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [21 November 2018 20:59 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/4 "2018-11-21T20:59:07Z")

</div>

> **[h2g2 - Number 42 Explained by Douglas Adams - Also Base 13 Explained](https://www.h2g2.com/entry/A4288584)**
>
> Number 42 Explained by Douglas Adams - Also Base 13 Explained, from h2g2, the Unconventional Guide to Life, the Universe and Everything

  
🙂

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [21 November 2018 21:05 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/5 "2018-11-21T21:05:46Z")

</div>

> [@BartButenaers](#):
>
> So if somebody now offers me a link to an existing node with similar functionality, I will most probably drop dead instantaneously

Uh oh... In the past, I've used [node-red-contrib-statistics](https://flows.nodered.org/node/node-red-contrib-statistics) to do things like sum, min, max, and mean on arrays of numbers. But there are lots of other supported functions that may or may not overlap with what you have -- according to the docs:

> - bernoulliDistribution
> - chunk
> - ckmeans
> - cumulativeStdNormalProbability
> - equalIntervalBreaks
> - errorFunction
> - extent
> - factorial
> - inverseErrorFunction
> - gamma
> - geometricMean
> - harmonicMean
> - interquartileRange
> - medianAbsoluteDeviation
> - max
> - mean
> - median
> - min
> - mode
> - poissonDistribution
> - probit
> - product
> - quantile
> - quantileRank
> - rootMeanSquare
> - sample
> - sampleWithReplacement
> - sampleKurtosis
> - sampleSkewness
> - sampleStandardDeviation
> - shuffle
> - standardDeviation
> - sum
> - sumNthPowerDeviations
> - tTest
> - uniqueCount
> - variance

But I do applaud you for seeing a need and jumping right on it!

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [21 November 2018 21:16 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/6 "2018-11-21T21:16:02Z")

</div>

> [@shrickus](#):
>
> But there are lots of other supported functions that may or may not overlap with what you have -- according to the docs

I have been guessing who wanted to see me dropping dead instantaneously, by passing me a node name. But Steve, I had never expected it would be you 🤨

Seems there is a small overlap between our nodes, but yours is for users above 7 years old. Mine is aimed at the remaining user group ... But now at least they can compare both nodes here, when they search the forum for 'math'. Thanks for the link!

> [@cymplecy](#):
>
> Number 42 Explained by Douglas Adams

Simon, it looks to me that you have been waiting about 3 years (until somebody would release a node-red-contrib-math node) to post that link. But I'm very proud of you 😉

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [21 November 2018 21:45 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/7 "2018-11-21T21:45:51Z")

</div>

> [@BartButenaers](#):
>
> I have been guessing who wanted to see me dropping dead instantaneously, by passing me a node name.

Well, now I think it's clear that this is not working out according to my "master plan"... 😏

---

<div class="post-metadata">

### Author: ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)
#### Post date: [22 November 2018 10:47 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/8 "2018-11-22T10:47:21Z")

</div>

Hi Bart,

It is a nice node.

Some feature request suggestions:

1. the ability to multiply/divide/add/subtract the payload with a value that can be configured in the node.  
1.1. this value can be a constant, but it can also be a flow or global context variable.
2. To round a number to configurable number of decimals.
3. Currently you are applying the math to the msg.payload. It would be interesting if you can specify the source for the math like is done in the change node. Especially it would be interesting if you could apply the math to a different field of the msg.

I also think that time arithmetic functions is an interesting area for extension or a separate node.  
E.g. adding `X minutes` or `Y hours` to a certain timestamp.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [22 November 2018 19:08 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/9 "2018-11-22T19:08:26Z")

</div>

> [@BartButenaers](#):
>
> As usual, all 'constructive' feedback is more than welcome

This will be useful for "quick and dirty" situations when it's not worth bothering with JavaScript or JSONata. Two observations:

- It would be good to have the option of getting the result in a message property other than `payload`, so that the incoming payload could be preserved for use downstream.
- It would be really nice to be able to choose the operation to be performed with the incoming message (perhaps with `msg.operation`), so that the same `math` node could be used to process different messages differently.

Perhaps more effort than you want to invest, but since (based on the rest of this thread) your life seems to be in danger, why not?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [22 November 2018 21:14 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/10 "2018-11-22T21:14:16Z")

</div>

Just noticed that npm [already has a node-red-contrib-math](https://www.npmjs.com/package/node-red-contrib-math) node registered, don't know if you are aware.

Paul

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [22 November 2018 21:46 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/11 "2018-11-22T21:46:02Z")

</div>

Hi Paul,

Yes indeed I have seen that node a couple of days ago, but there was no readme and I couldn't find the repository anywhere. So I left it behind... But what is more worse: I completely forgot about it 😖 Damn, I have even forgotten to install it at have a look at the source code. I'm getting old ...

Thanks anyway, I will have to rename mine to e.g. **node-red-contrib-basic-math** , or **node-red-contrib-mathematic**....  
Bart

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [22 November 2018 21:49 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/12 "2018-11-22T21:49:27Z")

</div>

**node-red-contrib-maths**?

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [22 November 2018 22:55 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/13 "2018-11-22T22:55:42Z")

</div>

Maths? The author might be mistaken for British. 😊

---

<div class="post-metadata">

### Author: ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)
#### Post date: [23 November 2018 09:00 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/14 "2018-11-23T09:00:31Z")

</div>

2 other suggestions for the name (maybe exist already ... so to check):

- **node-red-contrib-calc**
- **node-red-contrib-calculator**

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [24 November 2018 20:29 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/15 "2018-11-24T20:29:16Z")

</div>

@BartButenaers, I haven't installed this yet (I'm waiting for the name change & publication), but can each of the functions be changed dynamically by a corresponding msg property, instead of, or overriding the setting in the node config.  
ie msg.maximum or msg.minimum.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [24 November 2018 21:40 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/16 "2018-11-24T21:40:09Z")

</div>

Evening guys,

Based on all the useful feedback, I have changed a series of things:

1. The node has been renamed on Github to [node-red-contrib-calc](https://github.com/bartbutenaers/node-red-contrib-calc/blob/master/README.md)
2. When the operation dropdown is set to an empty value, the input message needs to have a `msg.operation` field (containing e.g. 'sqrt' for Square Root). That was already available in my first version, but I hadn't documented it yet in the readme and the info panel ...
3. Both the input and output field messages can now be changed on the config screen:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/da459eaf3f13d0d6656a9d424f6c9649b13ee640.png)
4. A new operation has been added to round the input number to a specified number of decimal places:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/374a283835ee96196a54b49f0ee3cc82dbde9298.png)
5. Examples have been added to the readme page
6. A link to the node-red-contrib-statistics node has been added to the readme page
7. I have added a field to the config screen, where a fixed constant number can be entered:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c740cd0cb1989c6b94c4f8dd87704949429a5dba.png)  
But that is not entirely complete yet ...  
@janvda: How it works now. For example you want to round number 1.23456 to 3 decimals:
  - Normally you need to apply an input message containing an array [1.23456 , 3]
  - However when you enter 3 in the constant field, the input message will only need to contain the number 1.23456 (and the calc-node will internally create an array [1.23456 , 3]. Is that sufficient ?

> [@Paul-Reed](#):
>
> can each of the functions be changed dynamically by a corresponding msg property, instead of, or overriding the setting in the node config. ie msg.maximum or msg.minimum.

Hey Paul, are you talking about point '2' ?

> [@janvda](#):
>
> I also think that time arithmetic functions is an interesting area for extension or a separate node.  
> E.g. adding `X minutes` or `Y hours` to a certain timestamp.

Hi Jan, haven't searched yet but I would 'expect' that something like that should be possible with other time-related nodes (like [node-red-contrib-simpletime](https://www.npmjs.com/package/node-red-contrib-simpletime), or [node-red-contrib-moment](https://www.npmjs.com/package/node-red-contrib-moment), or ...)?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [24 November 2018 21:44 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/17 "2018-11-24T21:44:21Z")

</div>

> [@BartButenaers](#):
>
> Hey Paul, are you talking about point '2' ?

Yes, that will be useful for what I've got in mind.  
Thanks

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [24 November 2018 22:06 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/18 "2018-11-24T22:06:01Z")

</div>

> [@BartButenaers](#):
>
> A new operation has been added to round the input number to a specified number of decimal places:

Don't you mean rounding the output?

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [24 November 2018 22:17 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/19 "2018-11-24T22:17:51Z")

</div>

> [@cymplecy](#):
>
> Don't you mean rounding the output?

Well I'm not native English speaking, so let's try it again: _I round the input number to get a an rounded output number_. Don't forget that we have to learn the English language by looking at television shows from your country like Monty Python, Mister Bean and Fawlty Towers. I'm not from Barcelona, but I still know nothing 🕶

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [25 November 2018 08:28 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100/20 "2018-11-25T08:28:08Z")

</div>

How about contacting the author of contrib-math to see if they have any interest in maintaining their node and if not, offer to take over the package?

[Next page](https://discourse.nodered.org/t/announce-node-red-contrib-math/5100.md?page=2)
