Rounder A Number Up!!

Ask a Question related to ASP, Design and Development.

  1. #1

    Default Rounder A Number Up!!

    I am dividing a value by two..what i need is to round the number up if it is
    not a whole number.

    Any suggestions on how to do this ??

    Help appreciated!!

    AK


    Adam Knight Guest

  2. Similar Questions and Discussions

    1. int Number to text Number Function / UDF ?
      Is there a function that converts e.g. 3 to Three? Probably not but I just thought I'd ask.
    2. Number to hex ?
      Looking at a few scripts, too disguise ID numbers or make them random, there appears to be a conversion to an alphanumeric number. e.g....
    3. sort from the smallest number to the highest number
      Hi Just say I want to sort the row by using the fifth column data as reference from the smallest the largest number, if using sort, It will give...
    4. sh: bad number
      Hi, I compiled a simple program with perl. But I ran into some problems. sh: campusUnderAttack.out: bad number I try to execute a program and...
    5. tty-dev-number <-> /dev/pts
      Hi, I'm writing a program under Solaris (sparc) that has to know from what machine a user is logged on who is starting that program. Reading...
  3. #2

    Default Re: Rounder A Number Up!!

    See if the number is not an integer, and if so, convert it to an integer and
    add one.

    Cheers
    Ken

    "Adam Knight" <aj.knight@optusnet.com.au> wrote in message
    news:%231IM5OoeDHA.3228@tk2msftngp13.phx.gbl...
    : I am dividing a value by two..what i need is to round the number up if it
    is
    : not a whole number.
    :
    : Any suggestions on how to do this ??
    :
    : Help appreciated!!
    :
    : AK
    :
    :


    Ken Schaefer Guest

  4. #3

    Default Re: Rounder A Number Up!!

    Cint(number+0.5)

    or

    Cint(number) + 1

    --

    ==========================================
    Hyper A.R.T.
    bart plessers
    Paul Van Ostaijenlaan 4
    3001 Heverlee
    BELGIUM
    tel: +32 (16) 23.40.85
    fax: +32 (16) 23.41.06
    ==========================================





    "Adam Knight" <aj.knight@optusnet.com.au> wrote in message
    news:#1IM5OoeDHA.3228@tk2msftngp13.phx.gbl...
    > I am dividing a value by two..what i need is to round the number up if it
    is
    > not a whole number.
    >
    > Any suggestions on how to do this ??
    >
    > Help appreciated!!
    >
    > AK
    >
    >

    bart plessers Guest

  5. #4

    Default Re: Rounder A Number Up!!

    sounds like a ceiling function

    [url]http://www.vb2themax.com/Item.asp?PageID=CodeBank&Cat=110&ID=24[/url]

    vb2themax has the code

    Function Ceiling(Number)
    Ceiling = -Int(-Number)
    End Function


    "Adam Knight" <aj.knight@optusnet.com.au> wrote in message
    news:#1IM5OoeDHA.3228@tk2msftngp13.phx.gbl...
    > I am dividing a value by two..what i need is to round the number up if it
    is
    > not a whole number.
    >
    > Any suggestions on how to do this ??
    >
    > Help appreciated!!
    >
    > AK
    >
    >

    ljb Guest

  6. #5

    Default Re: Rounder A Number Up!!

    Actually, I just dealt with this...

    intScreens = (cnItems.RecordCount Mod 15) + Int(cnItems.RecordCount /
    15)

    MOD will return a zero if there is no remainder and a one if there is.
    Int forces the number to be a whole number, therefore getting ride of
    everything past the decimal.

    I'm sure you can figure out how to apply this to what you need to do.

    hth,
    Andrew

    DEVBuilder.org, [url]http://www.DEVBuilder.org[/url]
    ASP,ASP.NET,VB.NET,PHP,Java,and SQL Support, all in one place.
    Andrew J Durstewitz Guest

  7. #6

    Default Re: Rounder A Number Up!!

    On 15 Sep 2003 15:56:14 GMT, Andrew J Durstewitz
    <adurstew@devbuilder.org> wrote:
    >Actually, I just dealt with this...
    >
    >intScreens = (cnItems.RecordCount Mod 15) + Int(cnItems.RecordCount /
    >15)
    >
    >MOD will return a zero if there is no remainder and a one if there is.
    >Int forces the number to be a whole number, therefore getting ride of
    >everything past the decimal.
    >
    >I'm sure you can figure out how to apply this to what you need to do.
    >
    MOD does not return zero or one. The MOD operator returns the
    remainder after division. It can be a very helpful operator in certain
    cases.

    A typical case where I have used it is to cycle through a number of
    items, once per day. I take a date, do some date math to determine the
    number of days since that date till now, then use MOD to figure out
    which item to display...

    s(0) = "First Item"
    s(1) = "Second Item"
    s(2) = "Third Item"
    s(3) = "Fourth Item"
    s(4) = "Fifth Item"

    itm = s(datediff("d", "9/11/2001", now) mod 5)

    After dividing the number of days since 9/11, the MOD operator returns
    the remainder. Let's say there were only 2 days since 9/11. 2 MOD 5
    returns 2, so the s(2) would be returned. On the third day 3 MOD 5
    returns 3, so s(3) would be returned.

    Later, when it's 303 days after 9/11, 303 MOD 5 returns 3 (303 divided
    by 5 is 60 with a remainder of 3).
    Dan Brussee Guest

  8. #7

    Default Re: Rounder A Number Up!!

    My bad, I mis-stated what I was trying to say. Your correct.

    However, if you use the MOD the poster will be able to round up.
    Basically if the MOD return is greater than 1 it's not a whole number.
    Turn it into an integer and add 1. Now it's the next higher number and
    whole.

    Andrew

    DEVBuilder.org, [url]http://www.DEVBuilder.org[/url]
    ASP,ASP.NET,VB.NET,PHP,Java,and SQL Support, all in one place.
    Andrew J Durstewitz Guest

  9. #8

    Default Re: Rounder A Number Up!!

    On 15 Sep 2003 17:26:15 GMT, Andrew J Durstewitz
    <adurstew@devbuilder.org> wrote:
    >My bad, I mis-stated what I was trying to say. Your correct.
    >
    >However, if you use the MOD the poster will be able to round up.
    >Basically if the MOD return is greater than 1 it's not a whole number.
    >Turn it into an integer and add 1. Now it's the next higher number and
    >whole.
    >
    Dont mean to harp on it, but how would MOD tell you if it's a whole
    number? It's really meant to be used with integers

    17 MOD 5 returns 2

    All numbers are whole.

    Dan Brussee Guest

  10. #9

    Default Re: Rounder A Number Up!!

    "Adam Knight" wrote:
    >
    > I am dividing a value by two..what i need is to round the
    > number up if it is not a whole number.
    Whatever you do, avoid CInt. Here's why (see the section on Bankers
    Rounding)...
    [url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;q196652[/url]
    ....as well as the [Note] here:
    [url]http://msdn.microsoft.com/library/en-us/script56/html/vsfctCInt.asp[/url]

    In short, here's a decent VBScript implementation of a "ceiling" function:

    Function RoundUp(val)
    RoundUp = Int(val) + Sgn(val - Int(val))
    End Function

    Just in case you care about negative numbers, consider what behavior you
    want for negative values before implementing this. "Rounding up" means
    that -1.2 rounds to -1. If you prefer that -1.2 round to -2, use something
    like this:

    Function RoundUp(val)
    RoundUp = Fix(val) + Sgn(val - Fix(val))
    End Function

    JScript is simpler, in a way. The first example above is merely:

    Math.ceil(val)

    The second is a bit trickier. Here are two implementations:

    1. val/Math.abs(val) * Math.ceil(Math.abs(val))
    2. val > 0 ? Math.ceil(val) : Math.floor(val)

    Enjoy exploring this.


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.


    Dave Anderson Guest

  11. #10

    Default Re: Rounder A Number Up!!

    "Dan Brussee" wrote:
    >
    > Dont mean to harp on it, but how would MOD tell you if it's
    > a whole number? It's really meant to be used with integers
    "The modulus, or remainder, operator divides number1 by number2 (rounding
    floating-point numbers to integers) and returns only the remainder as
    result."
    [url]http://msdn.microsoft.com/library/en-us/script56/html/vsoprmod.asp[/url]

    *** HOWEVER ***
    Mod uses Banker's Rounding, so it should be avoided at all costs:

    1.5 Mod 10 is 2
    2.5 Mod 10 is 2


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.


    Dave Anderson Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139