Divide miles, speed time formatting

Discussion in 'Programming' started by AimyThomas, Oct 16, 2012.

  1. #1
    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?
     
    AimyThomas, Oct 16, 2012 IP
  2. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #2
    Multiply it by 60.

    <?php
    $sum = round(11 / 55,1);// example 11 miles
    $cal = $sum * 60;
    echo $cal." minutes";
    ?>
    PHP:
     
    scottlpool2003, Oct 23, 2012 IP
  3. jadexe

    jadexe Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #3
    He only wanted to multiple the decimals not the whole number.
    
    <?php
    $sum = round(11 / 55,1);// example 11 miles
    
    $hours = floor($sum);
    $minutes = ($sum-hours) * 60;
    
    echo $hours. " hours and " .$minutes. " minutes";
    ?>
    
    PHP:
     
    jadexe, Oct 23, 2012 IP
  4. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #4
    I must've misread when he wanted it to display "12 minutes"
     
    scottlpool2003, Oct 24, 2012 IP
  5. jadexe

    jadexe Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #5
    I can't tell whether that's sarcasm or not. If it is:

     
    jadexe, Oct 24, 2012 IP
  6. Maximlis

    Maximlis Member

    Messages:
    179
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #6
    Don't have any idea about PHP. If anybody knows, please help.
     
    Maximlis, Oct 24, 2012 IP
  7. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #7
    No not sarcasm, I misread.

    Your code does output an error though, but the fixed code:

    <?php
    $sum = round(11 / 55,1);// example 11 miles
    
    $hours = floor($sum);
    $minutes = ($sum-$hours) * 60;
    
    echo $hours. " hours and " .$minutes. " minutes";
    ?>
    PHP:
     
    scottlpool2003, Oct 24, 2012 IP
  8. jadexe

    jadexe Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #8
    Sorry about that. :rolleyes:

    oops I was testing my code with a fresh installation of xampp and it had error_display disabled.
     
    jadexe, Oct 24, 2012 IP