?
Solved

RoundUp in Access VBA

Posted on 2013-12-19
9
Medium Priority
?
596 Views
Last Modified: 2013-12-19
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?
0
Comment
Question by:marku24
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 1000 total points
ID: 39730549
Try:

Int([Your Number]+0.99999)

Open in new window

0
 

Author Closing Comment

by:marku24
ID: 39730567
that is just ridiculously simple, but it does work.

thanks
0
 
LVL 75
ID: 39730605
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 21
ID: 39730648
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
 

Author Comment

by:marku24
ID: 39730661
thank you very much.
0
 
LVL 75
ID: 39730702
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
 
LVL 21
ID: 39730776
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
 

Author Comment

by:marku24
ID: 39730782
will do.  I am looking for rounding up only and will adjust accordingly.
0
 
LVL 53

Expert Comment

by:Gustav Brock
ID: 39731160
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question