I want to get rid of the decimals.
My function node is like this:
gas = parseFloat(msg.payload.svalue1);
msg.payload = gas;
msg.topic = "gas";
The outcome data is like:
gas : msg.payload : number
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?
You can use
toFixed if you want a fixed number of DP's. Just be aware that it turns the number into text though.
Here is an example in a
msg.payload = Math.trunc(msg.payload)
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
Thank you all. All sugestions were helpfull. Finanaly I used the Math.round code and it is working very well.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.