Round to Nearest Integer in Access

G

Guest

I need to round numbers in Access to the nearest integer, where I'd round up
if .5 or greater else round down. For example, need to round 33.5 to 34 and
33.2 to 33. I do not want to simply change the properties of the field...I
want the actual rounded number to populate the cell. Thanks!
 
D

David Lloyd

Renee:

Have you tried using the Round function? It takes two parameters, the value
and the number of decimals places to round to. The default is zero decimal
places (an integer).

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I need to round numbers in Access to the nearest integer, where I'd round up
if .5 or greater else round down. For example, need to round 33.5 to 34 and
33.2 to 33. I do not want to simply change the properties of the field...I
want the actual rounded number to populate the cell. Thanks!
 
G

Guest

Hay Renee

You can also use the function round, it might be better
round(MyNumber)
 
G

Guest

Use the Integer function -
Syntax: INT(number) Rounds a number down to the nearest integer.

Number is the real number you want to round down to an integer.

Example
Data = 19.5
Formula Description (Result)
=INT(8.9) Rounds 8.9 down (8)
=INT(-8.9) Rounds -8.9 down (-9)
=A2-INT(A2) Returns the decimal part of a positive real number in cell A2
(0.5)
 
A

Alan Armstrong

If you incorporate a bit of elementary maths and use INT(number+0.5) it will
always round to the nearest integer. For gimmicky supermarket 'rounding
down' change the 0.5 to fit the store's exact criteria.

Alan
 
D

datadyl

Neither the "Round" function nor the "Format" function will do what the
original poster requested, that is:

round up if .5 or greater, else round down.
For example, need to round 33.5 to 34 and 33.2 to 33

Both of your solutions--and those of most everyone else responding to this
type of a problem--will round 33.5 to 33 NOT 34.

Does anyone else know how to round numbers UP which have .5 or greater in
the number AND round DOWN those which have less than .5 in their number??

Thanks
 
J

Jeff Boyce

Here's a potential solution I found by searching on-line:

Question: I read your explanation of the Round function using the
round-to-even logic. However, I really need to round some values in the
traditional sense (where 5 always rounds up). How can I do this?

Answer: You could always use the following logic:

If you wanted to round 12.65 to 1 decimal place in the traditional sense
(where 12.65 rounded to 1 decimal place is 12.7, instead of 12.6), try
adding 0.000001 to your number before applying the Round function:

Round(12.45+0.000001,1)

By adding the 0.000001, the expression that you are rounding will end in
1, instead of 5...causing the Round function to round in the traditional
way.

And the 0.000001 does not significantly affect the value of your
expression so you shouldn't introduce any calculation errors.

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top