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 => {
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' >> 10.33
- '9:45' >> 9.75
- '15:33' >> 15.55
10:20
in the last line, not10.20
? \$\endgroup\$