RoundUp in Access VBA

I am trying to round a number (double) up to the next integer.  Here is a sample of the results I am looking for:

 1.25 rounds to 2
 .333 rounds to 1
 1.8 rounds to 2
1.111 rounds to 2

and so forth.  Anyone have a function to do this?
marku24Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPConnect With a Mentor Commented:
Try:

Int([Your Number]+0.99999)

Open in new window

0
 
marku24Author Commented:
that is just ridiculously simple, but it does work.

thanks
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Of course, this fails:

int(1.000001 +.999999)
 = 1
as well as other cases.

This never fails:

-Int(-[YourNumber)

-int(-1.000001)
= 2

Thanks for Gustav (cactus_data) for this trick.
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
Great trick to round down a negative.

This also works. You must force the data type for teh math.

? int(CDbl(1.000001 +.999999))
2
0
 
marku24Author Commented:
thank you very much.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Fails:
int(CDbl(1.0000000001 +.999999))
 =1

:marku24:
if you want accuracy, use this to Round up:
-Int(-[YourNumber])

Round down:

Int(YourNumber)

mx
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
I agree that -Int(-[YourNumber]) eliminates the chances for errors in accuracy. It should be the preferred method.

And it works for negative numbers!
? -int(-(-1.1))
-1 

Open in new window

0
 
marku24Author Commented:
will do.  I am looking for rounding up only and will adjust accordingly.
0
 
Gustav BrockCIOCommented:
Thanks Joe!

I should add that I can't take the credit, I'm rather the messenger. The method is as old as BASIC itself.

/gustav
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.