# Quick easy one - function node limit digits - Solved

**URL:** https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549
**Category:** General
**Tags:** function-node
**Created:** [17 February 2022 18:36 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549 "2022-02-17T18:36:18Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)
#### Post date: [17 February 2022 18:36 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549/1 "2022-02-17T18:36:18Z")

</div>

Quick one and deffo suffering a brain freeze.  
I need this line to limit the number of digits after the decimal point.  
`var mph = parseFloat (wind) * 0.44704;`  
I've used the syntax somewhere else in my flows, but after 10 mins still can't find it...  
I will one day tidy up my many many tabs of flows...  
TIA

---

<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: [17 February 2022 18:43 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549/2 "2022-02-17T18:43:31Z")

</div>

```auto
var mph = parseFloat (wind) * 0.44704;
mph = Math.round(mph*100)/100; // number

```

or use

```auto
mph = mph.toFixed(2); // string
```

---

<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: [17 February 2022 19:07 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549/3 "2022-02-17T19:07:05Z")

</div>

What are you doing that requires you to throw away accuracy like this? Usually it is best to delay rounding until you are, for example, displaying it. Many dashboard nodes allow you to do that at the moment of display.

---

<div class="post-metadata">

### Author: ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)
#### Post date: [17 February 2022 19:15 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549/4 "2022-02-17T19:15:19Z")

</div>

Hi, it's being fed into Home Assistant. It comes in as a M/S wind speed without decimal places, using the multiplication results in 8 digits after the decimal where two will be enough for what it's used for 😉

---

<div class="post-metadata">

### Author: ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)
#### Post date: [17 February 2022 19:17 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549/5 "2022-02-17T19:17:33Z")

</div>

> [@E1cid](#):
>
> `mph = mph.toFixed(2);`

I used this one, seems easier to understand.  
Many thanks. 😍

---

<div class="post-metadata">

### Author: ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)
#### Post date: [17 February 2022 19:21 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549/6 "2022-02-17T19:21:43Z")

</div>

Thanks all

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/77b7781a6c0e49d123fbc3e1f2e123e4eacf47d5.png)

---

<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: [3 March 2022 19:22 UTC](https://discourse.nodered.org/t/quick-easy-one-function-node-limit-digits-solved/58549/7 "2022-03-03T19:22:04Z")

</div>

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