Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ric Carey 50 posts 93 karma points
    Feb 27, 2012 @ 12:45
    Ric Carey
    0

    Rounding up a variable

    hi all,

    how do i round up a variaible? im doing a paging system and need to divdie the list size by the list total. However if its an odd number you need another page. how can i round the variable up so?

    Probabbly really simple but it escapes me at the moment.

     

    Cheers

  • Ric Carey 50 posts 93 karma points
    Feb 27, 2012 @ 14:08
    Ric Carey
    0

    Ive tried

      var amountOfPages = listTotal / listSize;
      var amountofPagesRounded = (int)System.Math.Ceiling((double)amountOfPages);

    but it still produces the figure rounded down.

     

    eg listTotal is 5 and listsize is 2 should be 2.5 rounded to 3 but it produces 2?

    Any help is aprectaited.

  • Rodion Novoselov 694 posts 859 karma points
    Feb 27, 2012 @ 14:22
    Rodion Novoselov
    1

    Hi,

    var p = listTotal / listSize + Math.Sign(listTotal % listSize);

    :-)

  • Ric Carey 50 posts 93 karma points
    Feb 27, 2012 @ 14:48
    Ric Carey
    0

    Works like a dream cheers

Please Sign in or register to post replies

Write your reply to:

Draft