# String to number problem

**URL:** <https://discourse.nodered.org/t/string-to-number-problem/42439>\
**Category:** General\
**Created:** [11 March 2021 00:23 UTC](https://discourse.nodered.org/t/string-to-number-problem/42439 "2021-03-11T00:23:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rufus](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@Rufus](https://discourse.nodered.org/u/Rufus)\
**Post date:** [11 March 2021 00:23 UTC](https://discourse.nodered.org/t/string-to-number-problem/42439/1 "2021-03-11T00:23:25Z")

</div>

Hello  
I am scarping data from a web and I need to change from string to number. If I try to use this:  
msg.payload = Number(msg.payload);  
return msg  
It doesn´t work for me as in Spain we use "," as "."  
The fisrt debug is the data I want to change to number and the second one is what I get.  
 ![Screenshot_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cd08acf721baaa0e7fb5f63564b7a6d693d95d2e.png)  
If the value is 0 it works fine.  
Any idea how can I do it?

(PD: Sorry for my english 🙂 )

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 March 2021 00:40 UTC](https://discourse.nodered.org/t/string-to-number-problem/42439/2 "2021-03-11T00:40:15Z")

</div>

a quick google search finds this [How to change commas into dots with JavaScript](https://flaviocopes.com/how-to-comma-dot-javascript/)

---

<div class="post-metadata">

**Author:** ![henrycosta05](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henrycosta05/32/36350_2.png) [@henrycosta05](https://discourse.nodered.org/u/henrycosta05)\
**Post date:** [11 March 2021 00:56 UTC](https://discourse.nodered.org/t/string-to-number-problem/42439/3 "2021-03-11T00:56:43Z")

</div>

hi @Rufus,  
Are you using function node?  
try trim() values befor number().

if you are using change node, try it

> **[String functions · JSONata](https://docs.jsonata.org/string-functions.html#trim)**
>
> \## \`$string()\`

if you know the maximum length of each array element that you realy want, you could test element length and exclude element [0] and [1] (for exemple) from your array. it will result in a new array that you can really convert to number.

---

<div class="post-metadata">

**Author:** ![Rufus](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@Rufus](https://discourse.nodered.org/u/Rufus)\
**Post date:** [11 March 2021 01:07 UTC](https://discourse.nodered.org/t/string-to-number-problem/42439/4 "2021-03-11T01:07:11Z")

</div>

Thanks for the quick response guys  
I tried @zenofmud solution and it worked, thank you.  
 ![Screenshot_2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20b4364babee8d8b32ab38946c5a9c4a9e83acce.png)

Next time I´ll try simple google seaches 🙂

---

<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:** [25 March 2021 01:07 UTC](https://discourse.nodered.org/t/string-to-number-problem/42439/5 "2021-03-25T01:07:38Z")

</div>

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