SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast AimyThomas's Avatar
    Join Date
    Sep 2011
    Posts
    46
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Divide miles, speed time formatting

    Hi, I am trying to display in minutes, instead of 0.2 hr etc
    like the example below will do, now I know every .1 = 6 min
    I am just stumped on how to get this to display 12 minutes.

    PHP Code:
    $sum = round(11 / 55,1);// example 11 miles
    echo $sum;
    I am trying to display things in minutes only when under 1 hour
    Anyone know how to multiply just that number after the decimal by 6?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    $hours floor(round(11 55,1));
    $minutes = (round(11 55,1) - $hours) * 6;

    echo 
    "$hours hours and $minutes minutes"
    Something like that?

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,147
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Another option is to use modulus.
    PHP Code:
    $remainder$time 1// $time = 5.1, $remainder = .1
    $minutes $remainder 10 6

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I looked for modulus, couldn't find it (I was expecting something like mod() ... )

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,147
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    I looked for modulus, couldn't find it (I was expecting something like mod() ... )
    for a reference http://php.net/manual/en/language.op...arithmetic.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •