# Convert Data from String to Number

**URL:** <https://discourse.nodered.org/t/convert-data-from-string-to-number/63875>\
**Category:** General\
**Tags:** database, function-node, mqtt\
**Created:** [13 June 2022 19:55 UTC](https://discourse.nodered.org/t/convert-data-from-string-to-number/63875 "2022-06-13T19:55:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SammyJang](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@SammyJang](https://discourse.nodered.org/u/SammyJang)\
**Post date:** [13 June 2022 19:55 UTC](https://discourse.nodered.org/t/convert-data-from-string-to-number/63875/1 "2022-06-13T19:55:55Z")

</div>

Hello life savers,  
I'm using sensors to send data from Node-Red to AWS IoT by using MQTT out.  
In the begining, there was no battery data in the payload so I set the change node to put the battery data in the payload(Someone helped me doing this Thank you so much). Just like the pictures.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd045630e5b572f01eedfa6068751315a7c162c1.png)

 ![Forum_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c1d07f4a48cf48b1c0d542e8db9aea7bf211e54b.jpeg)  
 ![Untitled 4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0ca9565ae9129e2ab63131005e3f576108441f19.jpeg)

But there is a small problem in the data type. Which is the data type of battery\_percent is not a number but string. So the data is not automatically being displayed on the AWS graph. Do you guys have any idea to convert the data type?

Thank you so much for every help that you can give me! Have a nice day!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 June 2022 20:10 UTC](https://discourse.nodered.org/t/convert-data-from-string-to-number/63875/2 "2022-06-13T20:10:16Z")

</div>

You can convert to number in the change node if you switch to JSONata type input

 ![chrome_screenshot_1655150899899](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abe35bbbfd64f996eaf5dc643c1b6eb7792e9647.jpeg)

---

<div class="post-metadata">

**Author:** ![SammyJang](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@SammyJang](https://discourse.nodered.org/u/SammyJang)\
**Post date:** [13 June 2022 20:50 UTC](https://discourse.nodered.org/t/convert-data-from-string-to-number/63875/3 "2022-06-13T20:50:35Z")

</div>

Thank you so much for the quick answer with the appropriate solution!

---

<div class="post-metadata">

**Author:** ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)\
**Post date:** [13 June 2022 20:54 UTC](https://discourse.nodered.org/t/convert-data-from-string-to-number/63875/4 "2022-06-13T20:54:19Z")

</div>

Am I correct in saying that the data is ingested via a serial port? Why don't you change the code on the device sending the data to you to send you a int/float?

---

<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:** [27 June 2022 20:54 UTC](https://discourse.nodered.org/t/convert-data-from-string-to-number/63875/5 "2022-06-27T20:54:37Z")

</div>

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