| View previous topic :: View next topic |
yancho Site Admin
Joined: 13 Nov 2007 Posts: 58 Location: Iklin
|
Posted: Mon Dec 10, 2007 4:36 pm Post subject: Rounding time |
|
|
|
I have come to a small problem where I can find no function that can round time! round() rounds decimal figures but it cannot (it does but wrong) round minutes / hours.
I have this data 0.270230000000000 saved as a numeric format in my PG table. This is some xml describing this row :
| Quote: |
<attr>
<attrlabl Sync="TRUE">FT_COST</attrlabl>
<attalias Sync="TRUE">FT_COST</attalias>
<attrtype Sync="TRUE">String</attrtype>
<attwidth Sync="TRUE">5</attwidth>
<attrdefs>Wake County addressing team (GIS)</attrdefs>
<attrdef>Enhanced Routing - Travel time in minutes
</attrdef>
</attr>
|
How can I make that 0.270230000000 into minutes / seconds ? Any hint is much appreicated!
Thanks _________________
 |
|
| Back to top |
|
|
yancho Site Admin
Joined: 13 Nov 2007 Posts: 58 Location: Iklin
|
Posted: Tue Dec 11, 2007 12:15 pm Post subject: |
|
|
|
This is how I worked around it .. any other suggestions please bring them forward :
| php: |
$totalsec = $ttime * 60 ; // to make it seconds
if ( intval ($totalsec) >= 60 ) {
//that means more than 1 minutes
$min_remainder = fmod ((intval ($totalsec)), 60);
$min = intval ((intval ($totalsec)) / 60);
}
else { $min = 0; }
$sec = round (($totalsec + $min_remainder),0);
$tajm = $min.":".$sec;
|
_________________
 |
|
| Back to top |
|
|
maldman
Joined: 13 Nov 2007 Posts: 7
|
Posted: Tue Dec 11, 2007 3:05 pm Post subject: |
|
|
|
prob thats exactly how i would of worked it out  |
|
| Back to top |
|
|
yancho Site Admin
Joined: 13 Nov 2007 Posts: 58 Location: Iklin
|
Posted: Tue Dec 11, 2007 7:51 pm Post subject: |
|
|
|
| maldman wrote: | prob thats exactly how i would of worked it out  |
hehe thanks for the suggestions  _________________
 |
|
| Back to top |
|
|
yancho Site Admin
Joined: 13 Nov 2007 Posts: 58 Location: Iklin
|
Posted: Fri Dec 21, 2007 6:05 pm Post subject: |
|
|
|
A bug was noticed that the seconds were not computed carefully.
Further investigation showed that I had to fix this function .. and here is how it is now .. should work fine :
| php: |
<?
$time = $_GET['time'];
function make_time ($totalsec) {
// echo $totalsec;
if ($totalsec >= 60) {
$min = intval($totalsec / 60);
$totalsec -= $min * 60;
}
$tajm = sprintf("%02d:%02d", $min, intval($totalsec));
return $tajm;
}
echo $time." is : ".make_time($time) ;
?> |
You can test it here : http://yancho.no-ip.org/~yancho/mt.php?=time=364.588889
Remember to change the value of time so you can test other figures
Hope it helps u
_________________
 |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
Powered by phpBB © 2001, 2002 phpBB Group |
|
|