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

**URL:** <https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973>\
**Category:** General\
**Created:** [30 December 2022 22:15 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973 "2022-12-30T22:15:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [30 December 2022 22:15 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973/1 "2022-12-30T22:15:51Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 December 2022 22:21 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973/2 "2022-12-30T22:21:21Z")

</div>

`toFixed()`

Actually does return a string

you might want to use

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

```

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

---

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [30 December 2022 22:36 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973/3 "2022-12-30T22:36:47Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 December 2022 22:41 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973/4 "2022-12-30T22:41:55Z")

</div>

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

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c4d364cfcaf7422daaff8a95deac07862983f815.png)

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c45e5c57f3218ea230918600a57b0af8f22915e.png)

---

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [30 December 2022 22:58 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973/5 "2022-12-30T22:58:14Z")

</div>

Thank you so much - really appreciated

---

<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:** [13 January 2023 22:58 UTC](https://discourse.nodered.org/t/saving-a-msg-payload-value-as-an-integer-help-needed/72973/6 "2023-01-13T22:58:42Z")

</div>

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