# Maths stuff not working between machines

**URL:** https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009
**Category:** General
**Created:** [8 October 2021 08:51 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009 "2021-10-08T08:51:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [8 October 2021 08:51 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009/1 "2021-10-08T08:51:47Z")

</div>

This is weird.

Forgetting previous stuff here is the problem I now am seeing/have.

This code:

```auto

counter = counter + 1;
context.set("COUNTER",counter);

node.warn("TOTAL is " + total);
total = total + x;
node.warn("TOTAL IS NOW " + total);
context.set("total",total);

msg.payload = total;

return msg;

```

This is what I see - given I `reset` the flow at the start. (Sorry it scrolled off the top of the screen)

 ![Screenshot from 2021-10-08 19-47-19](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/0821ac4c32bca931381906f5d651d9f9ea51e9e5.png)

NR 2.0.1

It starts at `0` and each time I press the `8` it increments by `8`.

On the **OTHER** machine....

This is what I'm getting:

 ![Screenshot from 2021-10-08 19-50-17](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c65dbd6e217015c0c5a8a4d148e320d760377538.png)

NR 1.2.6  
The _maths_ isn't being honoured.  
It would seem that it is being parsed as text.... and the new messages appended to the previous message instead of being added.

---

<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: [8 October 2021 09:05 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009/2 "2021-10-08T09:05:14Z")

</div>

You will find the context value total or the variable new\_value is a string. Use parseInt to convert it to a number before adding the new number.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [8 October 2021 09:06 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009/3 "2021-10-08T09:06:47Z")

</div>

But why is it working on the other machine?

Or (sorry) is that for 1.2.6 and was fixed in 2.0.1?

---

<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: [8 October 2021 09:07 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009/4 "2021-10-08T09:07:39Z")

</div>

Because on the other machine they will be numbers. When you add two numbers you get a number. When you add a string and a number it gets concatenated.

Just make sure they are both numbers by using parseInt.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [8 October 2021 09:07 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009/5 "2021-10-08T09:07:57Z")

</div>

Thanks.

I'm stupid.  
😉

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [8 October 2021 09:19 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009/7 "2021-10-08T09:19:16Z")

</div>

> [@Steve-Mcl](#):
>
> Just make sure they are both numbers by using parseInt.

Unless they are not integers, in which case use parseFloat. In fact I would just use Number() which will convert it based on the contents.

---

<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: [22 October 2021 09:19 UTC](https://discourse.nodered.org/t/maths-stuff-not-working-between-machines/52009/8 "2021-10-22T09:19:39Z")

</div>

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