Conversion does not work for me?


i am reading several float values from Global and add them up in parameter payload:

var v1 =  global.get('V.S.Power')||0; 
var v2 =  global.get('V.N.Power')||0; 
var v3 =  global.get('V.O.Power')||0;

msg.payload =  v1 + v2 + v3;

To get a nice value for my Dashboard I try to convert the value to an INT:

msg.payload = parseInt(msg.payload);

But no matter what I try, I always get a FLOAT value instead of an INT ... showing dozens of digits behind the coma :frowning:
What am I doing wrong ?


Do you return the msg after setting payload?

Yes, I return two msg-Objects:

return [msg,msg2];

I pass the msg to a dashboard text Node using {{msg.payload}}

Try .toFixed(0);

msg.payload = parseInt(msg.payload).toFixed(0);

I suspect you are returning an array to the text display in the dashboard
ie. [7, 12345]
can we see a debug of the function output?

And what is in msg2?
Do you have 2 outputs on the function?
which msg (msg or msg2) is the one going to this dashboard item?

msg2 is another value but is independent, ignore it

yes, I have 2 outputs, the first one (msg) goes to the dashboard, ignore msg2 :slight_smile:

Put a debug node on the output going to the ui node and show us what it says.

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