I have a question about formatting a string or float.
So essentially I have these numbers which need to be outputted as shown:
9.8333333333333 -> 09:50
5.5555555555556 -> 05:33
10.545454545455 -> 10:33
1.3333333333333 -> 01:20
20.923076923077 -> 20:55
Here is the function I wrote that is doing a terrible job at what I need it to.
function getTime($dist, $road) {
$roads = array('I' => 65, 'H' => 60, 'M' => 55, 'S' => 45);
$time = $dist / $roads[$road];
return round($time -1) . ':' . substr((float)explode('.', $time)[1] * 60, 0, 2);
}
So if anyone has any ideas id appreciate it, i've tried the DateTime class but wasn't able to format the numbers properly for it to be used.
Thanks.