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 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Division by zero

    I get this error

    Warning: Division by zero in /home/sites//public_html/mini.php on line 155

    Line 155 is

    $percent = round((($rankp-$old)/($max-$old))*100);

  • #2
    Regular Coder
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    118
    Thanks
    8
    Thanked 2 Times in 2 Posts
    One, some or all of your variables does not have a value.

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts
    What ?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    ($max - $old) * 100 = 0. You can't divide by 0; it is a mathematical impossibility.

  • #5
    New Coder
    Join Date
    Jan 2009
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts
    So what do i need to put.

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can check to see if ($max - $old) * 100 is equal to zero prior to dividing by it.

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Actually just check to see if $max-$old equal 0 before you divide by it since the * 100 is outside of the parentheses.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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