1. ## Rounding (2000)

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

Thanks,
Eric

2. ## 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. ## 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

4. ## 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.

Eric

5. ## 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. ## 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. ## 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.

8. ## 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.

9. ## 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
•