# Remove one digit and round payload value via function node

**URL:** https://discourse.nodered.org/t/remove-one-digit-and-round-payload-value-via-function-node/81370
**Category:** General
**Tags:** function-node
**Created:** [16 September 2023 15:33 UTC](https://discourse.nodered.org/t/remove-one-digit-and-round-payload-value-via-function-node/81370 "2023-09-16T15:33:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.nodered.org/u/kolia)
#### Post date: [16 September 2023 15:33 UTC](https://discourse.nodered.org/t/remove-one-digit-and-round-payload-value-via-function-node/81370/1 "2023-09-16T15:33:06Z")

</div>

Hello,  
I would like to adjust the decimal places of a value from a temperature sensor. The sensor delivers a payload with e.g. 22.68, the last digit should be omitted and rounded, so in this case a new payload of 22.7 should be output. This should be feasible via a function node, unfortunately everything I have found and tried so far has not worked. Unfortunately I do not know anything about programming. What should I put in the function?

---

<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: [16 September 2023 16:18 UTC](https://discourse.nodered.org/t/remove-one-digit-and-round-payload-value-via-function-node/81370/2 "2023-09-16T16:18:20Z")

</div>

You can do that with either a function node or a change node (with JSONata). Usually the output will be a string rather than a number however. Probably fine if you are simply displaying it.

To be honest, I have to look that up as well. If you have access to ChatGPT or Bing Chat or similar, it will tell you the answer, otherwise a simple internet search something like "javascript round to 1 decimal place" should do the job.

---

<div class="post-metadata">

### Author: ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.nodered.org/u/kolia)
#### Post date: [16 September 2023 17:04 UTC](https://discourse.nodered.org/t/remove-one-digit-and-round-payload-value-via-function-node/81370/3 "2023-09-16T17:04:49Z")

</div>

have found a workarround with the calculate node:  
multiply wirh 1 and round with one decimals

---

<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: [16 September 2023 17:42 UTC](https://discourse.nodered.org/t/remove-one-digit-and-round-payload-value-via-function-node/81370/4 "2023-09-16T17:42:27Z")

</div>

`msg.payload = Math.round(msg.payload *10)/10`  
Presuming msg.payload is a number.

---

<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: [15 November 2023 17:43 UTC](https://discourse.nodered.org/t/remove-one-digit-and-round-payload-value-via-function-node/81370/5 "2023-11-15T17:43:06Z")

</div>

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