tags:

views:

60

answers:

4
+2  Q: 

Decimal minutes

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

+3  A: 

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.

Daniel DiPaolo
+4  A: 
$decTime = 1.4;
$hour = floor($decTime);
$min = round(60*($decTime-$hour));
James Burgess
+1  A: 

Floor the number to get how many hours. Number - floored value [the decimal] * 60 = minutes [round it after]

ItzWarty
+1  A: 

Hours: floor( decimal )
Minutes: round( ( decimal * 60 ) mod 60 )

James is right about the rounding. I forgot to account for that. Adjusted.

fireeyedboy