Hello!
I would like to delete the decimal places on a number?
Whats the best way to do this?
Thanks in advance.
For what reason?
Do you require a string returned or a number
Is the input a number or a string?
Best to provide examples of input and required output.
It depends what you want to do with it. If you are formatting it for display then, if for example it is in msg.payload, in a function node
msg.payload = msg.payload.toFixed(0)
will convert it to a string containing the nearest integer. However, if you want to keep using it as a number then
msg.payload = Math.floor(msg.payload)
will convert it to the integer below the number, or
msg.payload = Math.round(msg.payload)
will convert it to the nearest integer.
Hello!
Thanks for the answer. This is exactly what I was looking for.
Hello @madmax
Why are you delete the decimal places ?
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.