Round to Nearest Integer in Access

Round to Nearest Integer in Access

Post by UmVuZW » Wed, 08 Jun 2005 02:38:01


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!
 
 
 

Round to Nearest Integer in Access

Post by T2Zlc » Wed, 08 Jun 2005 03:20:05

Try
format(dd,"#")

 
 
 

Round to Nearest Integer in Access

Post by David Lloy » Wed, 08 Jun 2005 03:20:44

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://www.yqcomputer.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!
 
 
 

Round to Nearest Integer in Access

Post by T2Zlc » Wed, 08 Jun 2005 03:21:07

Sorry the - dd represent the number
 
 
 

Round to Nearest Integer in Access

Post by T2Zlc » Wed, 08 Jun 2005 03:51:07

Hay Renee

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

Round to Nearest Integer in Access

Post by SmltS » Wed, 08 Jun 2005 05:00:02

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)
 
 
 

Round to Nearest Integer in Access

Post by Alan Armst » Wed, 08 Jun 2005 12:05:52

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
 
 
 

Round to Nearest Integer in Access

Post by ZGF0YWR5b » Sat, 15 Nov 2008 08:10:01

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
 
 
 

Round to Nearest Integer in Access

Post by Jeff Boyc » Sat, 15 Nov 2008 09:25:18

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