# Multiply and add (manually entered) numbers

**URL:** <https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692>\
**Category:** General\
**Created:** [5 April 2021 09:45 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692 "2021-04-05T09:45:03Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![PinPat](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PinPat](https://discourse.nodered.org/u/PinPat)\
**Post date:** [5 April 2021 09:45 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/1 "2021-04-05T09:45:04Z")

</div>

I have three manually entered numbers. I want to multiply two numbers and then add third numbers.  
Can someone please assist in choosing right palette and flow.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 April 2021 09:55 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/2 "2021-04-05T09:55:33Z")

</div>

Manually entered where? And where should the result go? On the dashboard? Show us what you have and what you want to achieve

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 April 2021 09:55 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/3 "2021-04-05T09:55:45Z")

</div>

You should be able to enter and add numbers using the ui dasboard node  
here is an example

```auto
[{"id":"c80bbf28.a5eed8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"colour","v":"red","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3660,"wires":[["755df129.aebf08"]]},{"id":"755df129.aebf08","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"1000","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"thousand","topicType":"str","min":0,"max":"10","step":1,"x":230,"y":3680,"wires":[["c900bea7.7f1108"]]},{"id":"c900bea7.7f1108","type":"join","z":"5a245aa1.510164","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":400,"y":3740,"wires":[["46e3c0d7.c48b5"]]},{"id":"46e3c0d7.c48b5","type":"function","z":"5a245aa1.510164","name":"","func":"let thousands = (msg.payload.thousand || 0) * 1000,\nhundreds = (msg.payload.hundred || 0) * 100,\ntens = (msg.payload.ten || 0) * 10,\nunits = msg.payload.unit || 0;\nmsg.payload.total = thousands + hundreds + tens + units;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":3800,"wires":[["8fb379e3.1e2938","64a84df4.8ed5cc"]]},{"id":"4c944021.62a4a","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"100","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"hundred","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3740,"wires":[["c900bea7.7f1108"]]},{"id":"2f0e72cd.eba9b6","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"10","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"ten","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3800,"wires":[["c900bea7.7f1108"]]},{"id":"8aea7870.00324","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"1","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"unit","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3860,"wires":[["c900bea7.7f1108"]]},{"id":"9a2d6f08.539b5","type":"inject","z":"5a245aa1.510164","name":"reset","props":[{"p":"reset","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":3940,"wires":[["c900bea7.7f1108"]]},{"id":"8fb379e3.1e2938","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":3740,"wires":[]},{"id":"64a84df4.8ed5cc","type":"ui_text","z":"5a245aa1.510164","group":"8b5cde76.edd58","order":8,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload.total}}","layout":"row-spread","x":580,"y":3880,"wires":[]},{"id":"33e2c29b.3e992e","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3740,"wires":[["4c944021.62a4a"]]},{"id":"34423f11.ece648","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3800,"wires":[["2f0e72cd.eba9b6"]]},{"id":"f4ec0a9.aefdcf8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3880,"wires":[["8aea7870.00324"]]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"6","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

If this does not help you will need to give more info.

---

<div class="post-metadata">

**Author:** ![PinPat](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PinPat](https://discourse.nodered.org/u/PinPat)\
**Post date:** [5 April 2021 10:14 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/4 "2021-04-05T10:14:31Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75641d8822b58fd4bf0f975332be69d008eb1720.png)

Left hand side figures are manually entered, to get Target temp.  
Target temp = (Actual temp+ (Duration\*(heating-cooling-rate(C/min))))

---

<div class="post-metadata">

**Author:** ![PinPat](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PinPat](https://discourse.nodered.org/u/PinPat)\
**Post date:** [5 April 2021 10:15 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/5 "2021-04-05T10:15:56Z")

</div>

Also please let me know how can i keep C/min figure restricted to two decimals.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 April 2021 10:21 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/6 "2021-04-05T10:21:59Z")

</div>

Lets take this in steps. The first step is to get all values in one place so you can do the maths.

Step 1

- Set the `topic` of each UI input to something suitable
  - avoid spaces and symbols. e.g. `actualTemp` instead of `Actual Temp`

- feed the values of these UI inputs into a join node
  - Set the join node to key/value object & a count of 4.

- Connect a debug node to the join node & try entering some values - you _SHOULD_ see all values in one payload.

Step 2

- after you complete step 1

---

<div class="post-metadata">

**Author:** ![PinPat](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PinPat](https://discourse.nodered.org/u/PinPat)\
**Post date:** [5 April 2021 11:34 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/7 "2021-04-05T11:34:07Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/65a6258984e9d86f8734732fb9ce7545d2b15756.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a46ef862f71222df13cb21c891150cc59bc806e7.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 April 2021 11:36 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/8 "2021-04-05T11:36:11Z")

</div>

So close 🙂

Change the `"using the value of msg. _______ as the key"` back to `msg.topic`

That way, your 4 values in the payload will be named as the topic you entered on the UI elements.

---

<div class="post-metadata">

**Author:** ![PinPat](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PinPat](https://discourse.nodered.org/u/PinPat)\
**Post date:** [5 April 2021 11:39 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/9 "2021-04-05T11:39:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3c60765613567d8d340190cd67de1302b96baa5.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 April 2021 11:53 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/10 "2021-04-05T11:53:50Z")

</div>

ok, so now you have all values in one place...

Step 2.

Connect the join node to a function node & enter...

```auto
//Target temp = (Actual temp+ (Duration*(heating-cooling-rate(C/min))))

var ActualTemp = msg.payload.ActualTemp;
var Ratehr = msg.payload.Ratehr;
var RateMin = msg.payload.RateMin;
var DurationMin = msg.payload.DurationMin;
msg.topic = "Target Temp";
msg.payload = (ActualTemp + (DurationMin * (Ratehr / RateMin))); // or whatever your calculation is
return msg;

```

Add a debug node after the function to check the output

---

<div class="post-metadata">

**Author:** ![PinPat](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PinPat](https://discourse.nodered.org/u/PinPat)\
**Post date:** [5 April 2021 12:32 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/11 "2021-04-05T12:32:28Z")

</div>

Thanks a lot Steve, Just one query, How can we restrict Function outcome to round figure?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8f69b1876a21b674c0f43d855106f48ea00bb771.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 April 2021 12:40 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/12 "2021-04-05T12:40:27Z")

</div>

You should never really round the value before display (as you lose precision)

However for display purposes, you can use angular decimal pipe for formatting in the UI text.

I don't remember the format off the top of my head. Something like `{payload | number:0}` Search the forum.

---

<div class="post-metadata">

**Author:** ![PinPat](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PinPat](https://discourse.nodered.org/u/PinPat)\
**Post date:** [5 April 2021 12:48 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/13 "2021-04-05T12:48:52Z")

</div>

Thanks Steve,  
I used .toFixed(0) at the end of msg.Payload.  
It works fine.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 June 2021 12:49 UTC](https://discourse.nodered.org/t/multiply-and-add-manually-entered-numbers/43692/14 "2021-06-04T12:49:38Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
