Hi not sure if this is the right forum for this but does anyone know the formula for converting decimal time in to hours and minutes ?
IE 1.4 = 1hr 24mins
thanks for any help and sorry if its the wrong forum
Hi not sure if this is the right forum for this but does anyone know the formula for converting decimal time in to hours and minutes ?
IE 1.4 = 1hr 24mins
thanks for any help and sorry if its the wrong forum
Simply take the decimal portion of the hours and multiply by 60 for the number of minutes.
In your example .4 (the decimal portion of 1.4) * 60 = 24 minutes
So if you need to do it in code, subtract the floor of the original number from the original number to get the decimal portion.
$decTime = 1.4;
$hour = floor($decTime);
$min = round(60*($decTime-$hour));
Floor the number to get how many hours. Number - floored value [the decimal] * 60 = minutes [round it after]
Hours: floor( decimal )
Minutes: round( ( decimal * 60 ) mod 60 )
James is right about the rounding. I forgot to account for that. Adjusted.