Results 1 to 9 of 9

Thread: Rounding (2000)

  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rounding (2000)

    Is there any easy way to round up to the next whole number using an expression?

    Thanks,
    Eric

  2. #2
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    USA
    Posts
    379
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rounding (2000)

    Try the VB Round function. It returns a number rounded to a specified number of decimal places. The syntax is:
    Round(expression [,numdecimalplaces])

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Rounding (2000)

    Do you always want to round up? e.g. do you want 2.01 to become 3 ?

    The Int function returns the integer portion of a number, so unless the number is already an integer, it always rounds down.
    So must of the time Int(number) +1 will be rounded up.
    so you could have this function

    public function fnroundup(number) as long
    if int(number) < number
    fnroundup = int(number) +1
    else
    fnroundup = number
    end if
    end function
    Regards
    John



  4. #4
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rounding (2000)

    Yes, I always want to round up from any fraction of a number. You said that this will work most of the time. So there are times that this wouldn't work?

    I was hoping that there was some kind of function or module I could use in an expression in a query. Do you know how I could do that? I tried creating a module with your code, but it wouldn't work. It brought back a result of #ERROR.

    Thanks for your help,
    Eric

  5. #5
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rounding (2000)

    Johns code will round up all of the time <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    He missed a "Then" off of his code but I assume that you found that if you got in a module ok.

    public function fnroundup(number) as long
    if int(number) < number Then
    fnroundup = int(number) +1
    else
    fnroundup = number
    end if
    end function

    I have tested his code from a query and it returned the expected data ok

    Exp1:fnroundup([lineSpeed])


    Not sure this helps you much though! apart from knowing the code is ok

  6. #6
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rounding (2000)

    Thanks alot! I tried to put in the "Then", but I must have put it in the wrong place or something. This works perfectly.

    Thanks again.

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Rounding (2000)

    Sorry about that, I often leave out Then then when I write if then statements, and get corrected by the compiler.

    I think it is because in Javascript you don't need it.
    Regards
    John



  8. #8
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Rounding (2000)

    What I meant was tht int(number) +1 will be correct most of the time ( except when number is an integer), so my suggested function should be correct all the time.
    Regards
    John



  9. #9
    Star Lounger
    Join Date
    Oct 2001
    Location
    Western Massachusetts, USA
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rounding (2000)

    This expression in a query will do what you want also

    NewNumber: -1*(Int(-1 * [Number]))

    Paul

Posting Permissions

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