# Restrict function output to one or two significant figures

**URL:** https://discourse.nodered.org/t/restrict-function-output-to-one-or-two-significant-figures/65740
**Category:** General
**Created:** [28 July 2022 09:36 UTC](https://discourse.nodered.org/t/restrict-function-output-to-one-or-two-significant-figures/65740 "2022-07-28T09:36:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Surefire01](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/surefire01/32/71490_2.png) [@Surefire01](https://discourse.nodered.org/u/Surefire01)
#### Post date: [28 July 2022 09:36 UTC](https://discourse.nodered.org/t/restrict-function-output-to-one-or-two-significant-figures/65740/1 "2022-07-28T09:36:51Z")

</div>

Hi folks.  
Trying to restrict the output of a function node to one or two significant figures. With the lines below I get ridiculously long numbers. Any of you coding experts know what I can add to achieve this?

1 msg.payload = msg.payload/60 (something here)  
2 return msg;

Thanks.

---

<div class="post-metadata">

### Author: ![Surefire01](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/surefire01/32/71490_2.png) [@Surefire01](https://discourse.nodered.org/u/Surefire01)
#### Post date: [28 July 2022 09:57 UTC](https://discourse.nodered.org/t/restrict-function-output-to-one-or-two-significant-figures/65740/2 "2022-07-28T09:57:25Z")

</div>

It's OK folks, I found the solution here from a previous post

[[How can I limit a simple math function to 2 decimal places](https://discourse.nodered.org/t/how-can-i-limit-a-simple-math-function-to-2-decimal-places/34294)]

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [28 July 2022 09:58 UTC](https://discourse.nodered.org/t/restrict-function-output-to-one-or-two-significant-figures/65740/3 "2022-07-28T09:58:25Z")

</div>

Are you doing this for display on a dashboard? If so, you should only round the number when you come to display it. Otherwise you lose precision.

In simple terms, leave the value as it is and only format it when you show it.

---

<div class="post-metadata">

### Author: ![Surefire01](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/surefire01/32/71490_2.png) [@Surefire01](https://discourse.nodered.org/u/Surefire01)
#### Post date: [28 July 2022 10:04 UTC](https://discourse.nodered.org/t/restrict-function-output-to-one-or-two-significant-figures/65740/4 "2022-07-28T10:04:47Z")

</div>

OK thanks for that Steve.

---

<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: [11 August 2022 10:05 UTC](https://discourse.nodered.org/t/restrict-function-output-to-one-or-two-significant-figures/65740/5 "2022-08-11T10:05:28Z")

</div>

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