# Number in German format in dashboard (100.235,25) - how to?

**URL:** <https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236>\
**Category:** General\
**Created:** [17 March 2020 15:45 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236 "2020-03-17T15:45:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [17 March 2020 15:45 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/1 "2020-03-17T15:45:23Z")

</div>

How can I format my msg.payload to be shown in German format in dashboard text node.  
not 100,235.25  
but 100.235,25  
for example.  
Any help appreciated.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [17 March 2020 17:29 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/2 "2020-03-17T17:29:29Z")

</div>

you could convert it to a string beforehand and do a regexreplace in a function node.  
Have a look at this function node:

```auto

[{"id":"2d6bb7f8.73721","type":"function","z":"c7988e96.f0bac","name":"","func":"if(typeof msg.payload != \"string\") msg.payload = String(msg.payload);\nif(msg.payload.match(/\\./g)) {\n msg.payload = msg.payload.replace(/\\,/g, \".\");\n msg.payload = msg.payload.replace(/\\.(?!.*\\.)/g, \",\");\n} else {\n msg.payload = msg.payload.replace(/\\,/g, \".\");\n}\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":500,"wires":[["6ae79d5c.bc65a4"]]}]

```

it checks if payload is a string and else converts it to a string.  
it than checks if the string contains a “.” (so it contains decimal places)  
it than replaces all “,” with a “.” and the last “.” with a comma using a negative look ahead.  
Else if the english format number string doesn’t have any decimal places it just replaces any “,” with “.”.  
Hope this helps, Johannes.

---

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [18 March 2020 10:30 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/3 "2020-03-18T10:30:06Z")

</div>

many thanks for your support. It works.  
I always thought, I could fix it with Angular filters.  
There is still a little problem. I am using a gauge to show current solar power. How can I change the dot to comma within the gauge?

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 March 2020 10:47 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/4 "2020-03-18T10:47:43Z")

</div>

Have a look at this:

```auto
[{"id":"47ab2415.2c4624","type":"ui_gauge","z":"2e26d7ec.3b45c","name":"","group":"28d9dd4.23e65a2","order":1,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{msg.numstring}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1630,"y":700,"wires":[]},{"id":"41c03c3b.86a264","type":"inject","z":"2e26d7ec.3b45c","name":"","topic":"","payload":"6.7","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1310,"y":700,"wires":[["a244754.c025788"]]},{"id":"a244754.c025788","type":"function","z":"2e26d7ec.3b45c","name":"","func":"let convert = msg.payload;\nif(typeof convert != \"string\") convert = String(convert);\nif(convert.match(/\\./g)) {\n convert = convert.replace(/\\,/g, \".\");\n convert = convert.replace(/\\.(?!.*\\.)/g, \",\");\n} else {\n convert = convert.replace(/\\,/g, \".\");\n}\nmsg.numstring = convert;\nreturn msg;","outputs":1,"noerr":0,"x":1470,"y":700,"wires":[["47ab2415.2c4624"]]},{"id":"28d9dd4.23e65a2","type":"ui_group","z":"","name":"Wohnung","tab":"93e51f49.a58cd8","order":1,"disp":false,"width":"6","collapse":false},{"id":"93e51f49.a58cd8","type":"ui_tab","z":"","name":"Übersicht","icon":"info","order":1,"disabled":false,"hidden":false}]

```

I changed the function node a little bit. It now assigns the converted value string to a new msg property msg.numstring instead of of overwriting the msg.payload.  
It than uses the msg.numstring value as a value format in the gauge node in the form of {{msg.numstring}}.  
This should do what you want.

---

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [18 March 2020 11:23 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/5 "2020-03-18T11:23:14Z")

</div>

> [@JGKK](#):
>
> [{"id":"47ab2415.2c4624","type":"ui\_gauge","z":"2e26d7ec.3b45c","name":"","group":"28d9dd4.23e65a2","order":1,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{msg.numstring}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1630,"y":700,"wires":},{"id":"41c03c3b.86a264","type":"inject","z":"2e26d7ec.3b45c","name":"","topic":"","payload":"6.7","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1310,"y":700,"wires":[["a244754.c025788"]]},{"id":"a244754.c025788","type":"function","z":"2e26d7ec.3b45c","name":"","func":"let convert = msg.payload;\nif(typeof convert != "string") convert = String(convert);\nif(convert.match(/\./g)) {\n convert = convert.replace(/\,/g, ".");\n convert = convert.replace(/\.(?!.\*\.)/g, ",");\n} else {\n convert = convert.replace(/\,/g, ".");\n}\nmsg.numstring = convert;\nreturn msg;","outputs":1,"noerr":0,"x":1470,"y":700,"wires":[["47ab2415.2c4624"]]},{"id":"28d9dd4.23e65a2","type":"ui\_group","z":"","name":"Wohnung","tab":"93e51f49.a58cd8","order":1,"disp":false,"width":"6","collapse":false},{"id":"93e51f49.a58cd8","type":"ui\_tab","z":"","name":"Übersicht","icon":"info","order":1,"disabled":false,"hidden":false}]

Thank you very much! It works!

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [18 March 2020 11:34 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/6 "2020-03-18T11:34:55Z")

</div>

[https://www.w3schools.com/jsref/jsref\_tolocalestring.asp](https://www.w3schools.com/jsref/jsref_tolocalestring.asp)

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 March 2020 11:46 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/7 "2020-03-18T11:46:14Z")

</div>

this was not about date time strings but actual number values. this only works for date objects as far as i can see. The peculiarity here is that in Germany we use a “,” instead of a “.” do show decimal places in numbers but all number values in programming languages are inherently in an english format.  
Edit i see it works for numbers too

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [18 March 2020 11:48 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/8 "2020-03-18T11:48:51Z")

</div>

Oops, read to quickly. BTW, I lived in Germany for 33 years 🙂

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [18 March 2020 11:52 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/9 "2020-03-18T11:52:17Z")

</div>

Actually, it does work for numbers too!

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 March 2020 12:26 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/10 "2020-03-18T12:26:57Z")

</div>

Hmm, I cant get it too work somehow:

```auto
var a = 66.5;
var b = a.toLocaleString('de-DE');

```

works in the browser but not in nodered

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [18 March 2020 12:28 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/11 "2020-03-18T12:28:42Z")

</div>

I just tried too, didn't work either!

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 March 2020 12:34 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/12 "2020-03-18T12:34:04Z")

</div>

So the regex way i proposed seams to be the preferable way still.  
would have been so much tidier with toLocaleString() but for some reason it doesnt work in nodered.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 March 2020 12:40 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/13 "2020-03-18T12:40:27Z")

</div>

so it seams to be node.js issue:

> <https://stackoverflow.com/questions/23199909/using-tolocalestring-in-node-js>

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 March 2020 13:01 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/14 "2020-03-18T13:01:26Z")

</div>

for future reference:  
You have to first install 'intl' with npm according to the nodered manual ([https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules](https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules)) so that you can use it in nodered functions.  
You have to `npm install intl` from the same directory as your settings.js file and add it to the function global context in the settings.js file like this:

```auto
functionGlobalContext: {
        intl:require('intl')
    },

```

and afterwards restart nodered.  
When this is done you can use it like this in a function node:

```auto
var intl = global.get('intl');
let a = msg.payload;
let b = intl.NumberFormat('de-De',{style:'decimal'}).format(a);
msg.payload = b;
return msg;

```

The input has to be of type number.  
maybe just use regex otherwise 🙈  
Best regards Johannes

---

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [19 March 2020 09:38 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/15 "2020-03-19T09:38:19Z")

</div>

actually I was trying to use intl.NumberFormat but with no success.  
Thanks to your post above, I think that I will manage to make it work in Node-Red.  
Perfect job, thanks!

---

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [19 March 2020 11:34 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/16 "2020-03-19T11:34:20Z")

</div>

Ok, I implemented intl and it works perfectly as long as it is de-DE decimal. Using de\_DE currency does not get a comma. So I used decimal and put an € sign in front of msg.payload in the Text-node.

---

<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:** [2 April 2020 11:34 UTC](https://discourse.nodered.org/t/number-in-german-format-in-dashboard-100-235-25-how-to/23236/17 "2020-04-02T11:34:24Z")

</div>

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