Solved

RoundUp in Access VBA

Posted on 2013-12-19
9
508 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 250 total points
Comment Utility
Try:

Int([Your Number]+0.99999)

Open in new window

0
 

Author Closing Comment

by:marku24
Comment Utility
that is just ridiculously simple, but it does work.

thanks
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
 
LVL 21
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:marku24
Comment Utility
thank you very much.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
Comment Utility
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
Comment Utility
will do.  I am looking for rounding up only and will adjust accordingly.
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now