# String to number convert

**URL:** <https://discourse.nodered.org/t/string-to-number-convert/66425>\
**Category:** General\
**Tags:** http-request\
**Created:** [14 August 2022 19:30 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425 "2022-08-14T19:30:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lorixx](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@Lorixx](https://discourse.nodered.org/u/Lorixx)\
**Post date:** [14 August 2022 19:30 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425/1 "2022-08-14T19:30:43Z")

</div>

Hi  
I am currently trying to read the consumption of my washing machine.  
My problem I can not separate the string so far that I have only the numbers.  
I have already tried with split node but no solution found.  
can someone help me?

 ![Screenshot 2022-08-14 100413](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d384a61d95a6be47009ae1a76de0e3895af9635.png)  
 ![ewf](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b910a4bfbd7323ec4feffbc5539bac070138cb3f.png)  
 ![Screenshot 2022-08-14 100318](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d71c8463b8c14fbbcd58157d3b89d2f2fde0b62f.png)  
Thanks for help 🙂

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [14 August 2022 20:01 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425/2 "2022-08-14T20:01:20Z")

</div>

Instead of a screen print, can you paste the string value (The 'copy value' button to the right of the value in the debug sidebar).

...also, you can select in the http request node to select 'a parsed JSON object', which would remove the need for a json node in your flow.

![json](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20d8675d942072c4b5ac60797337a033036c5189.jpeg)

---

<div class="post-metadata">

**Author:** ![Lorixx](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@Lorixx](https://discourse.nodered.org/u/Lorixx)\
**Post date:** [14 August 2022 20:17 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425/3 "2022-08-14T20:17:05Z")

</div>

thanks for the tip without the json node.  
the output from the hhtp request is then the following

```auto
{"type":"status","description":"Gesamtverbrauch","command":"ecomXstatXtotal","value":" 2,5 kWh,  534ℓ "}

```

Then I used the function node to take only the value

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [14 August 2022 20:54 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425/4 "2022-08-14T20:54:41Z")

</div>

I'm sure someone will produce a shorter/better way to achieve this, but meanwhile, try this;

 ![energy](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59c0e1ef027e5789eb5c7a5428c19a3a97a2f208.jpeg)

```auto
[{"id":"ae7f927eba3b434f","type":"inject","z":"8ec88bd9c36c3f6b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"status\",\"description\":\"Gesamtverbrauch\",\"command\":\"ecomXstatXtotal\",\"value\":\" 2,5 kWh,  534ℓ \"}","payloadType":"json","x":90,"y":560,"wires":[["09592e25093ad1d3"]]},{"id":"09592e25093ad1d3","type":"change","z":"8ec88bd9c36c3f6b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":255,"y":560,"wires":[["47a13779bf90e0e5"]]},{"id":"47a13779bf90e0e5","type":"csv","z":"8ec88bd9c36c3f6b","name":"","sep":" ","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":425,"y":560,"wires":[["e635f76538b1bd97"]]},{"id":"e635f76538b1bd97","type":"function","z":"8ec88bd9c36c3f6b","name":"Obtain energy","func":"const string = msg.payload.col2\nmsg.payload = Number(string.replace(\",\", \".\"))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":575,"y":560,"wires":[["f9e923ee9521431a"]]},{"id":"f9e923ee9521431a","type":"debug","z":"8ec88bd9c36c3f6b","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":560,"wires":[]}]

```

**EDIT -** The following post by @E1cid is a better solution !!

---

<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:** [14 August 2022 21:20 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425/5 "2022-08-14T21:20:24Z")

</div>

Not a bad way, could be improved on slightly using the columns input field to select which values are required, and to give property names.

```auto
[{"id":"ae7f927eba3b434f","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"status\",\"description\":\"Gesamtverbrauch\",\"command\":\"ecomXstatXtotal\",\"value\":\" 2,5 kWh,  534ℓ \"}","payloadType":"json","x":70,"y":240,"wires":[["09592e25093ad1d3","7fce01dc.4cafc"]]},{"id":"09592e25093ad1d3","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":",","fromt":"str","to":".","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"ℓ","fromt":"str","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":280,"wires":[["ead43a1.09bfe48"]]},{"id":"7fce01dc.4cafc","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":240,"wires":[["47a13779bf90e0e5"]]},{"id":"ead43a1.09bfe48","type":"csv","z":"30af2d3e.d94ea2","name":"","sep":" ","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":",kw,,,l","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":410,"y":280,"wires":[["f51c8aa4.4a2fe8"]]},{"id":"47a13779bf90e0e5","type":"csv","z":"30af2d3e.d94ea2","name":"","sep":" ","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":",kw,,,l","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":405,"y":240,"wires":[["f9e923ee9521431a"]]},{"id":"f51c8aa4.4a2fe8","type":"debug","z":"30af2d3e.d94ea2","name":"numbers","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":555,"y":280,"wires":[]},{"id":"f9e923ee9521431a","type":"debug","z":"30af2d3e.d94ea2","name":"strings","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":240,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Lorixx](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@Lorixx](https://discourse.nodered.org/u/Lorixx)\
**Post date:** [15 August 2022 16:18 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425/6 "2022-08-15T16:18:48Z")

</div>

Thanks for the help works perfectly 😀

---

<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:** [29 August 2022 16:19 UTC](https://discourse.nodered.org/t/string-to-number-convert/66425/7 "2022-08-29T16:19:17Z")

</div>

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