Convert minutes portion of time to decimal I am making an hours calculator app. It takes a start time, end time and time taken for lunch.
For the start and end time it takes a four-digit hh:mm time. For example: 10:20.
I have made a function which converts the time into a decimal,
so 10:20 = 10.33. The function works, but I feel it looks a little heavy and wondered if anyone has any suggestions of how I could make it better...
const minuteConverter = time =&gt; {
    let h = Number(time.split(':')[0]);
    let m = Math.round((1 / 60 * (Number(time.split(':')[1])) + Number.EPSILON) * 100) / 100;
    let mConverted = Number(m.toString().split('.')[1])
    return Number(`${h}.${mConverted}`)
};
console.log(minuteConverter('10:20'))

The time must be output as a number to two decimal places. For example,

'10:20' &gt;&gt; 10.33
'9:45' &gt;&gt; 9.75
'15:33' &gt;&gt; 15.55
Use const instead of let to declare variables if the value doesn't change.

You are executing time.split(':') twice.

A short method to convert a string to a number is the unary +.

JavaScript has the toFixed() method to format a number to a fixed number of digits:



function minuteConverter(time) {
   const [h, m] = time.split(':');
   const value = +h + +m / 60;
   return value.toFixed(2);
}