# Decimals places

**URL:** <https://discourse.nodered.org/t/decimals-places/67618>\
**Category:** Dashboard\
**Tags:** node-red-dashboard, function-node\
**Created:** [12 September 2022 16:09 UTC](https://discourse.nodered.org/t/decimals-places/67618 "2022-09-12T16:09:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erissin\_Industria4.0](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@Erissin\_Industria4.0](https://discourse.nodered.org/u/Erissin_Industria4.0)\
**Post date:** [12 September 2022 16:09 UTC](https://discourse.nodered.org/t/decimals-places/67618/1 "2022-09-12T16:09:23Z")

</div>

How to leave only two decimal places after the comma?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [12 September 2022 16:12 UTC](https://discourse.nodered.org/t/decimals-places/67618/2 "2022-09-12T16:12:06Z")

</div>

You need to provide more details as your question is "wide-open".

For example, I normally leave two decimal places after a DECIMAL POINT.  
Here's an example 21.46  
And here's another example 1246.25

---

<div class="post-metadata">

**Author:** ![Erissin\_Industria4.0](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@Erissin\_Industria4.0](https://discourse.nodered.org/u/Erissin_Industria4.0)\
**Post date:** [12 September 2022 16:23 UTC](https://discourse.nodered.org/t/decimals-places/67618/3 "2022-09-12T16:23:43Z")

</div>

That would be it, two decimal places after a decimal point, like the first example. The way I do it currently shows 14 decimal places in the right side of decimal point.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [12 September 2022 16:25 UTC](https://discourse.nodered.org/t/decimals-places/67618/4 "2022-09-12T16:25:39Z")

</div>

So where is that?  
For example in (a calculation in) a piece of JavaScript?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [12 September 2022 16:36 UTC](https://discourse.nodered.org/t/decimals-places/67618/5 "2022-09-12T16:36:05Z")

</div>

Here's a very simple example using a function node that rounds-up to two decimal places.

```auto
let mph = 21.4689;

msg.payload = Number(mph.toFixed(2));
return msg;

```

![round](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b93964b96fe847a89db6bcc4d0c8dc514892f154.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 September 2022 16:38 UTC](https://discourse.nodered.org/t/decimals-places/67618/6 "2022-09-12T16:38:40Z")

</div>

If you want to display it in the dashboard, many of the widgets have the ability to do that when it is displayed. Generally display time is the best time to throw away accuracy, it usually only humans that have a problem with high accuracy.

---

<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:** [12 September 2022 16:46 UTC](https://discourse.nodered.org/t/decimals-places/67618/7 "2022-09-12T16:46:51Z")

</div>

Those pesky mainland Europeans and their commas in numbers as decimal place.

```auto
msg.payload = "123,4567890";
let decimal_number = Number(msg.payload.replace(",", "."));
msg.payload = decimal_number.toLocaleString('de-DE', { maximumFractionDigits: 2 });

return msg;

```

---

<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:** [12 October 2022 16:47 UTC](https://discourse.nodered.org/t/decimals-places/67618/8 "2022-10-12T16:47:45Z")

</div>

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