SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Rounding up

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Montgomery, TX
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Rounding up

    Let's say I do this:

    10 / 3 = 3.33333

    What would I do to round up to 4? I'm displaying 3 photos per page. I calculate how many pages I need by dividing the number of photos by how many I display on each page. 10 photos / 3 photos per page should equal 4 pages, but round(10 / 3) gives 3.

    Solutions?

    Thanks,

    David

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dkroll
    Let's say I do this:

    10 / 3 = 3.33333

    What would I do to round up to 4? I'm displaying 3 photos per page. I calculate how many pages I need by dividing the number of photos by how many I display on each page. 10 photos / 3 photos per page should equal 4 pages, but round(10 / 3) gives 3.

    Solutions?

    Thanks,

    David
    Use ceil(). It will round UP your numbers.

    ie: $pages = ceil(10/3); // would equal 4
    Last edited by PHP John; May 23, 2003 at 21:36. Reason: To correct ciel() to ceil()... sheesh...:)
    John

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    correction, the function name is ceil()
    - website

  4. #4
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that's the one! (...I really dislike that word, "ceiling"...)
    John

  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what about floor() is that one better
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  6. #6
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At least I can spell "floor"!
    John

  7. #7
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol, with PHP, spelling counts
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


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
  •