Rounding time

 
Post new topic   Reply to topic    PHP User Group Malta Forum Index // PHP Projects
View previous topic :: View next topic  
Author Message
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 51
Location: Iklin

PostPosted: Mon Dec 10, 2007 4:36 pm    Post subject: Rounding time Reply with quote
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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 51
Location: Iklin

PostPosted: Tue Dec 11, 2007 12:15 pm    Post subject: Reply with quote

 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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
maldman



Joined: 13 Nov 2007
Posts: 7

PostPosted: Tue Dec 11, 2007 3:05 pm    Post subject: Reply with quote
prob thats exactly how i would of worked it out Rolling Eyes Laughing
Back to top
View user's profile Send private message
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 51
Location: Iklin

PostPosted: Tue Dec 11, 2007 7:51 pm    Post subject: Reply with quote
maldman wrote:
prob thats exactly how i would of worked it out Rolling Eyes Laughing


hehe thanks for the suggestions Razz
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 51
Location: Iklin

PostPosted: Fri Dec 21, 2007 6:05 pm    Post subject: Reply with quote

 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"$minintval($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 Smile

Hope it helps u Wink


_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Post new topic   Reply to topic    PHP User Group Malta Forum Index // PHP Projects All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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

alexisRed v1.2 // Theme Created By: Andrew Charron and Web Hosting Bluebook // Icons in Part By: Travis Carden
Boards optimised using the phpBB-SEO mod found at phpbb-seo.com
Boards hosted courtesy of solutions-lab.net
Link Backs : PHPClasses.org - MT Page :: PHPUsergroups.org - MT Page



Powered by phpBB © 2001, 2002 phpBB Group