How can I convert a double value to time? For example, if the input is 7.50
then the output would be 7.30
.
views:
60answers:
4
A:
- Find the integral part of the number: These are your hours
- Find the fractional part of the number; multiply it by 60 and round down (floor()). These are your seconds. That's all there is to it.
tdammers
2010-07-30 10:59:54
Thanks...............................
arnold
2010-07-30 11:14:43
+3
A:
Get only a nondecimal rest by
$val = $input - floor( $input );
Then convert values from 0-99 to 0-60 by (exactly it is 0.99... to 0.60):
$val = $val*0.6;
At the end add the computed precision value to the decimal part of the input:
$output = floor( $input ) + $val
killer_PL
2010-07-30 11:01:04
+2
A:
$input = "7.5";
list($hours, $wrongMinutes) = explode('.', $input);
$minutes = ($wrongMinutes < 10 ? $wrongMinutes * 10 : $wrongMinutes) * 0.6;
echo $hours . ':' . $minutes;
nikic
2010-07-30 11:02:34