Decimals places

How to leave only two decimal places after the comma?

You need to provide more details as your question is "wide-open".

For example, I normally leave two decimal places after a DECIMAL POINT.
Here's an example 21.46
And here's another example 1246.25

That would be it, two decimal places after a decimal point, like the first example. The way I do it currently shows 14 decimal places in the right side of decimal point.

So where is that?
For example in (a calculation in) a piece of JavaScript?

Here's a very simple example using a function node that rounds-up to two decimal places.

let mph = 21.4689;

msg.payload = Number(mph.toFixed(2));
return msg;

round

If you want to display it in the dashboard, many of the widgets have the ability to do that when it is displayed. Generally display time is the best time to throw away accuracy, it usually only humans that have a problem with high accuracy.

Those pesky mainland Europeans and their commas in numbers as decimal place.

msg.payload = "123,4567890";
let decimal_number = Number(msg.payload.replace(",", "."));
msg.payload = decimal_number.toLocaleString('de-DE', { maximumFractionDigits: 2 });


return msg;
3 Likes

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