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
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    Round Up Integer

    I am creating a function which will display the page number for a post in a thread on my forum. To calculate the page number I divide the total posts by the page size.

    Example:
    Posts in Thread: 12
    Page Size: 10
    Page Number: 12/10 = 1.2

    However when rounded off 1.2 becomes 1, whereas I need it to always round up. Is there a way of doing this?

    Thanks,
    Curt.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Math.Ceiling what you were looking for?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello Curt and nikkiH,

    Curt if you are using the PagedDataSource Class, you can use the CurrentPageIndex Property to get an output something like:

    Page 2 of 8

    Code:
    lblPageNumber.Text = "Page " & (PagedData.CurrentPageIndex + 1) & " of " & PagedData.PageCount
    In the above sample, PagedData is the instance of the PagedDataSource Class.

  • #4
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    This is for links to posts such as the one at the bottom of my homepage:

    http://www.rallystuff.net

    Instead of the thread links going to the first post I need to find a way of getting the page number. I have all the code done for it, I just need to find a way of rounding up.

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nikkiH solution will do the job:

    Math.Ceiling(2.2) = 3
    Math.Ceiling(2.7) = 3
    Math.Ceiling(2.0) = 2

  • #6
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Thats worked great

    Thank you to both you.


  •  

    Posting Permissions

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