Maths stuff not working between machines

This is weird.

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

This code:

counter = counter + 1;

node.warn("TOTAL is " + total);
total = total + x;
node.warn("TOTAL IS NOW " + 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)

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:

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.

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.

But why is it working on the other machine?

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

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.


I'm stupid.

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.

1 Like

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