# Delete the decimals

**URL:** <https://discourse.nodered.org/t/delete-the-decimals/76480>\
**Category:** General\
**Created:** [12 March 2023 17:58 UTC](https://discourse.nodered.org/t/delete-the-decimals/76480 "2023-03-12T17:58:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [12 March 2023 17:58 UTC](https://discourse.nodered.org/t/delete-the-decimals/76480/1 "2023-03-12T17:58:00Z")

</div>

Hello,  
I want to get rid of the decimals.  
My function node is like this:

```auto
gas = parseFloat(msg.payload.svalue1);
msg.payload = gas;
msg.topic = "gas";
return msg;

```

The outcome data is like:  
gas : msg.payload : number  
2437.604

or sometimes 2450.50

or sometimes 2730.3

I only want to use the whole numbers (integers).

How can i change the function code to only get the numbers before the decimal point?

---

<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:** [12 March 2023 18:29 UTC](https://discourse.nodered.org/t/delete-the-decimals/76480/2 "2023-03-12T18:29:08Z")

</div>

You can use `toFixed` if you want a fixed number of DP's. Just be aware that it turns the number into text though.

[Number.prototype.toFixed() - JavaScript | MDN (mozilla.org)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 March 2023 18:30 UTC](https://discourse.nodered.org/t/delete-the-decimals/76480/3 "2023-03-12T18:30:04Z")

</div>

I would do a google search using 'javascript how to strip decimals from number'

Here is an example in a `function` node

```auto
msg.payload = Math.trunc(msg.payload)
return msg;

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [12 March 2023 19:00 UTC](https://discourse.nodered.org/t/delete-the-decimals/76480/4 "2023-03-12T19:00:30Z")

</div>

well you could just use `parseInt` instead of paareFloat...  
but maybe you want to round to nearest integer instead in which case you could use `Math.round(gas)`.

---

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [13 March 2023 18:24 UTC](https://discourse.nodered.org/t/delete-the-decimals/76480/5 "2023-03-13T18:24:16Z")

</div>

Thank you all. All sugestions were helpfull. Finanaly I used the Math.round code and it is working very well.

---

<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:** [27 March 2023 18:25 UTC](https://discourse.nodered.org/t/delete-the-decimals/76480/6 "2023-03-27T18:25:05Z")

</div>

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