# Turn payload numbers into integer

**URL:** <https://discourse.nodered.org/t/turn-payload-numbers-into-integer/47399>\
**Category:** General\
**Created:** [20 June 2021 13:18 UTC](https://discourse.nodered.org/t/turn-payload-numbers-into-integer/47399 "2021-06-20T13:18:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [20 June 2021 13:18 UTC](https://discourse.nodered.org/t/turn-payload-numbers-into-integer/47399/1 "2021-06-20T13:18:56Z")

</div>

Hi everyone,

I probably have a really simple request - here is the use case. I receive temperature values ​​from my sensors, which I can call up through Alexa when needed. The problem now is, that these values have two decimal places, which makes it harder to understand when transmitted through Alexa speak. Therefore I´d like to truncate the payload of temperature values to integers that I can then use to create the message text. Anyone know if there is a simple solution for that?

---

<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:** [20 June 2021 13:27 UTC](https://discourse.nodered.org/t/turn-payload-numbers-into-integer/47399/2 "2021-06-20T13:27:14Z")

</div>

Hi .. you could use javascript's [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) in a function node or in a Change Node use the $round method of a Jsonata expression.

**Example Flow :**

```auto
[{"id":"f38d0c47e9c4c7e5","type":"inject","z":"f6e161f3e6088354","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"23.567","payloadType":"num","x":550,"y":500,"wires":[["74b61bddae0cd3d0","58ebd0ca3367f9d2"]]},{"id":"74b61bddae0cd3d0","type":"function","z":"f6e161f3e6088354","name":"parseInt","func":"msg.payload = parseInt(msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":460,"wires":[["60668ef870bd270b"]]},{"id":"60668ef870bd270b","type":"debug","z":"f6e161f3e6088354","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":460,"wires":[]},{"id":"58ebd0ca3367f9d2","type":"change","z":"f6e161f3e6088354","name":"jsonata round","rules":[{"t":"set","p":"payload","pt":"msg","to":"$round(payload, 0)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":560,"wires":[["e1bbbd3db019d854"]]},{"id":"e1bbbd3db019d854","type":"debug","z":"f6e161f3e6088354","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":560,"wires":[]}]

```

---

<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:** [20 June 2021 13:29 UTC](https://discourse.nodered.org/t/turn-payload-numbers-into-integer/47399/3 "2021-06-20T13:29:01Z")

</div>

There are multiple ways msg.payload.toFixed() will return a string with the value set to interger  
here are a couple of other ways

```auto
[{"id":"d91c7fc3.fce0c8","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1.23","payloadType":"num","x":100,"y":1480,"wires":[["aa0748cd.3d8a9","54b59e1e.722fa","7eb45134.6f573"]]},{"id":"aa0748cd.3d8a9","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$round(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":1480,"wires":[["896fbba5.052b98"]]},{"id":"54b59e1e.722fa","type":"function","z":"c74669a0.6a34f8","name":"","func":"msg.payload = parseInt(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":1520,"wires":[["896fbba5.052b98"]]},{"id":"7eb45134.6f573","type":"function","z":"c74669a0.6a34f8","name":"","func":"msg.payload =msg.payload.toFixed()\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":1560,"wires":[["896fbba5.052b98"]]},{"id":"896fbba5.052b98","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":1640,"wires":[]}]

```

it all depends if you want a string return or a number.

---

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [20 June 2021 13:40 UTC](https://discourse.nodered.org/t/turn-payload-numbers-into-integer/47399/5 "2021-06-20T13:40:33Z")

</div>

Thanks much @E1cid and @UnborN for the quick solution 🙂

---

<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:** [4 July 2021 13:41 UTC](https://discourse.nodered.org/t/turn-payload-numbers-into-integer/47399/6 "2021-07-04T13:41:04Z")

</div>

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