# Number of decimals i function

**URL:** https://discourse.nodered.org/t/number-of-decimals-i-function/4233
**Category:** General
**Created:** [23 October 2018 17:58 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233 "2018-10-23T17:58:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![SKL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/skl/32/38237_2.png) [@SKL](https://discourse.nodered.org/u/SKL)
#### Post date: [23 October 2018 17:58 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233/1 "2018-10-23T17:58:47Z")

</div>

How do i limit the number of decimals to 1 in this?

msg.payload = Number(msg.payload)  
msg.payload = (((msg.payload)\*10)-100)  
return msg;

My output is like this now  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/58745e469d2f9e58f47a5381391620c05d40c1bb.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: [23 October 2018 20:15 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233/2 "2018-10-23T20:15:37Z")

</div>

This is the second thread today that this has been discussed ([Problems using '.toFixed()'](https://discourse.nodered.org/t/problems-using-tofixed/4192)). It is generally best not to do this until you are about to display it, assuming that the reason you want to limit it is for display purposes. Don't throw away accuracy until the very last moment. Often the widget you are using for display has the ability to show numbers to a given number of decimals. See the other thread for how to use angular filters in dashboard nodes to do this.  
If you really do need to truncate in a function then look at the .toFixed() function as used in that thread.

---

<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: [23 October 2018 20:55 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233/3 "2018-10-23T20:55:04Z")

</div>

Do I sense a new load of college students starting their programming courses?!

---

<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: [24 October 2018 13:10 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233/4 "2018-10-24T13:10:23Z")

</div>

> [@TotallyInformation](#):
>
> Do I sense a new load of college students starting their programming courses?!

You could be right.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [24 October 2018 13:55 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233/5 "2018-10-24T13:55:08Z")

</div>

Which I hope as a community we welcome with patience, respect and gentle guidance, as a new group of people gain their first experiences of Node-RED, and possibly programming in general.

---

<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: [24 October 2018 13:58 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233/6 "2018-10-24T13:58:24Z")

</div>

Certainly, well I do my best. One of the reasons I tend to give pointers to how to do things rather than provide a full solution is that I think users learn more from working out how to do something with guidance rather than being handed it on a plate.

---

<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: [23 April 2020 00:57 UTC](https://discourse.nodered.org/t/number-of-decimals-i-function/4233/7 "2020-04-23T00:57:43Z")

</div>


