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

cast as int to remove value after "."

then parse

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);

Hi Bachov

Thanks for your code

Member Avatar for diafol

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!

Hi Bachov Varghese

Thanks.is working fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.