# Temperature sensor to round in Node-RED

**URL:** <https://discourse.nodered.org/t/temperature-sensor-to-round-in-node-red/54182>\
**Category:** Dashboard\
**Created:** [23 November 2021 21:38 UTC](https://discourse.nodered.org/t/temperature-sensor-to-round-in-node-red/54182 "2021-11-23T21:38:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiby007](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@tiby007](https://discourse.nodered.org/u/tiby007)\
**Post date:** [23 November 2021 21:38 UTC](https://discourse.nodered.org/t/temperature-sensor-to-round-in-node-red/54182/1 "2021-11-23T21:38:24Z")

</div>

Dear All!

I have a temperature sensor value coming from S7-300 PLC. I get the value in a long decimal format, which does not look good on a dashboard. I would like to round it to 1 decimal, like 23,5 Celsius. I have no Java experience, I tried to googled it, but after a few hours I decided to ask for help. At the moment my node looks like this:

 ![Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/54a72905806a90c8d313b4a62a398653bc78786a.jpeg)  
I am planning to use a function to round the value to 1 decimal, like 28,6.

In the function I tried several things, without success. My latest attempt looks like the following:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b6eed325f6fb2a8bcb109f345cfd9526ee8dee2f.png)

Can somebody give me a good example how to do that from the beggining untill the end?I did not find any good solution. In which tab should I write it? On start or Message?

My other problem is that at the moment the Gauge shows nothing: 0.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [23 November 2021 21:50 UTC](https://discourse.nodered.org/t/temperature-sensor-to-round-in-node-red/54182/2 "2021-11-23T21:50:18Z")

</div>

you dont need a function to round it .. you could but its not needed because that functionality is there in the Gauge config.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af2aad9278529cf03240f8359387aa3a55f06bfe.png)

where `| number: 1` defines the decimal points to use

> [@tiby007](#):
>
> My other problem is that at the moment the Gauge shows nothing: 0.

possibly because you used `toFixed` in the function that converts payload to a string and the gauge expects a number (not tested)

**Test:**

```auto
[{"id":"5a4ee787702b045b","type":"ui_gauge","z":"5847b7aa62131d37","name":"","group":"2f14c49684858048","order":0,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{msg.payload | number:1 }}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":580,"y":1060,"wires":[]},{"id":"58308cf632b9808f","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"23.3245435","payloadType":"num","x":360,"y":1060,"wires":[["5a4ee787702b045b"]]},{"id":"2f14c49684858048","type":"ui_group","name":"Default","tab":"8b65008e9fad5be6","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"8b65008e9fad5be6","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![tymarbut](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@tymarbut](https://discourse.nodered.org/u/tymarbut)\
**Post date:** [23 November 2021 21:53 UTC](https://discourse.nodered.org/t/temperature-sensor-to-round-in-node-red/54182/3 "2021-11-23T21:53:47Z")

</div>

In addition to the solution posted above, you could use the Smooth node (needs to be installed in Manage Palette -\> Install). It can be used for rounding values, and I use them frequently in conjunction with DS18B20 sensors.

---

<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 November 2021 22:03 UTC](https://discourse.nodered.org/t/temperature-sensor-to-round-in-node-red/54182/4 "2021-11-23T22:03:42Z")

</div>

> [@tiby007](#):
>
> My other problem is that at the moment the Gauge shows nothing: 0.

Add a debug node showing what you have going into the function node that you showed.  
For the formatting, `toFixed(1)` should work, but the best way is to do it in the gauge as suggested. Generally you should not throw away accuracy until you need to.

---

<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:** [7 December 2021 22:04 UTC](https://discourse.nodered.org/t/temperature-sensor-to-round-in-node-red/54182/5 "2021-12-07T22:04:19Z")

</div>

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