Quick easy one - function node limit digits - Solved

Quick one and deffo suffering a brain freeze.
I need this line to limit the number of digits after the decimal point.
var mph = parseFloat (wind) * 0.44704;
I've used the syntax somewhere else in my flows, but after 10 mins still can't find it...
I will one day tidy up my many many tabs of flows...

var mph = parseFloat (wind) * 0.44704;
mph =  Math.round(mph*100)/100; // number

or use

mph = mph.toFixed(2);  // string
1 Like

What are you doing that requires you to throw away accuracy like this? Usually it is best to delay rounding until you are, for example, displaying it. Many dashboard nodes allow you to do that at the moment of display.

Hi, it's being fed into Home Assistant. It comes in as a M/S wind speed without decimal places, using the multiplication results in 8 digits after the decimal where two will be enough for what it's used for :wink:

I used this one, seems easier to understand.
Many thanks. :heart_eyes:

Thanks all

1 Like

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