Saving a msg.payload value as an integer - Help needed

I have a global value which is an integer. I am passing it to a JOIN node before saving it to an Influxdb, but it appears to be saving as a string. I've sent the data from JOIN into a Debug Node, which shows the JSON data as a string.

I'm using a simple function

msg.payload = global.get("TodayDailyGeneration").toFixed(2);
msg.topic = "solar";
return msg;

toFixed()

Actually does return a string

you might want to use

msg.payload = parseFloat(global.get("TodayDailyGeneration").toFixed(2));
msg.topic = "solar";
return msg;

I think :sweat_smile: - i'm never fully confident with these things
better folk around here, if I'm incorrect.

Ah ha - I had tried parseint, but I see now I should have used parseInt !!!

Second question - related - how would I define the source in a Change node ?

You should use parseFloat if you have precision you need to retain (given you want 2 decimal places) :wink:

As for the change node.
you can set the root path as a dropdown (this can be chosen for both the target property and source property)

Screenshot 2022-12-30 at 22.40.30

or if you mean setting the payload with this formatting via a change node

set the to the value as $round($globalContext("TodayDailyGeneration"),2)

making sure to mark it as JSONata
Screenshot 2022-12-30 at 22.56.19

1 Like

Thank you so much - really appreciated

1 Like

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