# European to North American Number Change - Solved

**URL:** <https://discourse.nodered.org/t/european-to-north-american-number-change-solved/45513>\
**Category:** General\
**Created:** [11 May 2021 20:51 UTC](https://discourse.nodered.org/t/european-to-north-american-number-change-solved/45513 "2021-05-11T20:51:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [11 May 2021 20:51 UTC](https://discourse.nodered.org/t/european-to-north-american-number-change-solved/45513/1 "2021-05-11T20:51:51Z")

</div>

Is there a node, or suggested function Javascript to convert European formatted numbers to North American formatted numbers.

I have some Germans trying to use some flows I built, but the number formats are causing problems with "parseFloat" commands and the JSON parse node.

So, the flows I built in North America are not parsing correctly because of the different formats for floating numbers, i.e. when "14.074,000 (eu format) is "parseFloat" in a function, we get "14" instead of "14,074.000". So, Node-Red sees the "." as a decimal, instead of a "thousand" separator.

What is a simple Javascript code to convert European to North American number format:

North American example: 14,074.000  
European example: 14.074,000

Alan

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 May 2021 22:15 UTC](https://discourse.nodered.org/t/european-to-north-american-number-change-solved/45513/2 "2021-05-11T22:15:28Z")

</div>

You could mess with the JavaScript [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) functions maybe.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [11 May 2021 22:20 UTC](https://discourse.nodered.org/t/european-to-north-american-number-change-solved/45513/3 "2021-05-11T22:20:47Z")

</div>

Because you are using Parsefloat I'm assuming that the payload is a string.  
The easiest way is to search and replace the ., with the other one.

```auto
[{"id":"f956991c.7acad8","type":"inject","z":"6ebb4e1a.90e7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"14.074,000","payloadType":"str","x":130,"y":1220,"wires":[["bd0a0af5.41dd4","dc96ab08.15e268"]]},{"id":"bd0a0af5.41dd4","type":"change","z":"6ebb4e1a.90e7","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":".","fromt":"str","to":"*","tot":"str"},{"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":320,"y":1300,"wires":[["dc96ab08.15e268"]]},{"id":"dc96ab08.15e268","type":"debug","z":"6ebb4e1a.90e7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":1300,"wires":[]}]

```

However I doubt if this is the correct way. Normally the location of the decimal point and thousand separator is determined by the country settings of the operating system.  
If this is set this correct for your country I think that parseFloat needs to work fine.

---

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [12 May 2021 00:01 UTC](https://discourse.nodered.org/t/european-to-north-american-number-change-solved/45513/4 "2021-05-12T00:01:41Z")

</div>

Solved. The "BaldGeek", Ben, on another forum came up with the solution.

Using a function node:

str = msg.payload;  
msg.payload = str.replace('.', '#').replace(',', '.').replace('#', ',');  
return msg;

And, using a change node:

```auto
[{"id":"6f5ff02d.034d9","type":"change","z":"6773a439.5cfddc","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":".","fromt":"str","to":"#","tot":"str"},{"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":440,"y":2100,"wires":[["3fcbd991.7cfec6"]]},{"id":"cccb57ae.18de18","type":"inject","z":"6773a439.5cfddc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"14,074.000","payloadType":"str","x":240,"y":2060,"wires":[["6f5ff02d.034d9"]]},{"id":"fe645929.889508","type":"inject","z":"6773a439.5cfddc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"14.074,000","payloadType":"str","x":240,"y":2140,"wires":[["6f5ff02d.034d9"]]},{"id":"3fcbd991.7cfec6","type":"debug","z":"6773a439.5cfddc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":2100,"wires":[]}]

```

---

<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:** [26 May 2021 00:02 UTC](https://discourse.nodered.org/t/european-to-north-american-number-change-solved/45513/5 "2021-05-26T00:02:27Z")

</div>

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