I need to turn TIME into DECIMAL and then do the opposite operation. I created the functions as shown below, but the result was not efficient because, depending on the origin of the value, the result is different, even though it is the same Type.
Follow the Code:
<?php
// Nutro as variáveis com o mesmo valor e o mesmo tipo de Type
// Mas uma de forma direta e outra via uma function.
$A = 1.01694444444; // Esta dá o retorno errado da function Func_1
$B = Func_2('01:01:01'); // Esta dá o retorno correto da function Func_1
echo $A . '<br />' . $B;
echo "<br /><br />";
// Mas o resultado dos cálculos da function abaixo é diferente
echo Func_1($A) . '<br />' . Func_1($B);
function Func_2($time){
$hms = explode(":", $time);
return ($hms[0] + ($hms[1]/60) + ($hms[2]/3600));
}
function Func_1($dec){
$seconds = ($dec * 3600);
$hours = floor($dec);
$seconds -= $hours * 3600;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
return lz($hours).":".lz($minutes).":".lz($seconds);
}
function lz($num){
return (strlen($num) < 2) ? "0{$num}" : $num;
}
?>
I've looked everywhere, but I do not know how to solve it. Here is a LINK from the example above: link