SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could anyone give me some advise on how to round a number to the nearest whole number.

    $NumberToRound = Any number between 0 and 10 and could be a double, integer or 0.

    How do I get $NumberToRound to round to the nearest whole number??

    Cheers

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple.

    $number = 4.4;
    $rounded_number = round($number);
    /* $rounded_number equals "4" */


    Don't you love PHP?

  3. #3
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This thread had a series of discussions about different ways of rounding up or down etc etc..

    http://www.sitepointforums.com/showt...threadid=18137

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers, must have missed that function - very slick.

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I was just typing the following code into Homesite4.5 when a box popped up saying "number" and automatically changed the variable in the round() to number. Has it picked up on an obvious error in my code?

    Code where $SiteScore has following syntax:

    $SiteScore = "45_350_4";


    $Figures = explode("_", $SiteScore);
    $TotalVotes = ($Figures[0])+1;
    $MaximumPossibleScore = $TotalVotes*10;
    $SumOfScores = ($Figures[1])+($Score);
    $NewScore = ($MaximumPossibleScore)/$SumOfScores;
    $NewScore = round($NewScore); //error thrown by Homesite here


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
  •