Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Equation question

    Ok, first of all I know close to nothing when it comes to PHP. Yet I know enough to make a template using the simple 'echo' command.

    Here's the equation that I have, which works just fine.
    PHP Code:
    <? 
        $overall 
    = ($action $comedy $romancedrama $voiceacting $artwork $plotoriginality) / 6
    ?>
    This equation works just fine, but my only complaint is that it turns out as like 7.3333333333333333333333

    Is there any way that I could simply make it round up to the nearest tenth making it just display 7.3??

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, but sadly i cant understand anything of what was going on in that page. Its way way too advanced for me and I couldnt follow. Ok, instead of rounding, I just want it to display the first digit after the decimal..any ideas?

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    PHP Code:

    $overall 
    round((($action $comedy $romancedrama $voiceacting $artwork $plotoriginality) / 6),1); 
    What's hard about that?
    Last edited by Spookster; 01-30-2003 at 04:24 AM.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    for a decimal point or two, you might want number_format

    $overall = number_format( (full equation) , 2);

    or

    $overall = floatval( full equation );
    for PHP 4.2.0+
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #6
    New Coder
    Join Date
    Aug 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okii, THANK YOU!!!!! That was EXACTLY what I wanted to do. Thank God it was so simple, thank you very much!!


  •  

    Posting Permissions

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