0

Hi

can any one pls help on the below thing

I am having a value as

91819.0

But I required the above data should be converted as time as below

9:18:19

Likewise it should be viceversa

Edited by rpv_sen

4
Contributors
5
Replies
43
Views
3 Years
Discussion Span
Last Post by rpv_sen
1

Try this

function setMyValue ($myValue) {
$newValue = (int)$myValue;
$myArray = array_reverse(str_split($newValue));
$myValue ="";
foreach ($myArray as $key=>$myDigits) {
    $myValue.=($key>0 && $key%2==0) ? ":" : "";
    $myValue.= $myDigits;
}
return strrev($myValue);
}

echo setMyValue(91819.0);
0

Casting as int will not round the float to an integer. Well, actually I suppose it rounds down like ceil(). It simply truncates.

If you want the decimal part to be considered, then I suggest you use the round() function to get your integer.

So:

$time = strrev(implode(":", str_split(strrev(round($myValue)), 2)));

heh!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.