| |
|
| |
| |
|
Round Int Fix
Rounding Numbers with Round, Int, and Fix
Q: I have a situation where I need to round a number UP to
the next whole integer, but the ROUND function brings it to the nearest
integer. For example, I need 4.2 rounded UP to 5. How can I do this?
A: There are three functions
you should be familiar with when it comes to rounding numbers. The first
is the ROUND function. This will round off any decimal number to
the nearest integer. Anything over .5 will be rounded up. So 4.1 becomes
4, and 4.8 becomes 5.
Next you have the INT function. This rounds any decimal number
DOWN to the nearest integer. So 4.1 becomes 4, and 4.8 is also 4.
Finally you have the FIX function which rounds POSITIVE numbers
DOWN to the nearest integer, but rounds NEGATIVE numbers UP. So 4.1
becomes 4, and 4.8 becomes 4, but -4.1 becomes -5. The difference
between INT and FIX is simply how they handle negatives.

You can generate these values in a query simply by creating
calculated fields:

So to answer your question, if you always want to round a value UP to
the next integer, I would use INT(x)+1. This will use the INT function
to bring your value DOWN to the nearest integer. Then just add 1 to it.
| | |
Student Interaction:
New Access Tip: Rounding Numbers
|
Richard on 2/12/2009:
Sorry for the lack of new material or even blog posts. I've been so busy recording new material.
I did have time today, however, to add a new Access Tip. I get asked ALL the time how to round numbers in different ways in Access. There are THREE functions you should be familiar with:
Round, Fix, and Int
Knowing how to use these three functions will give you all the tools you need to round off numbers ANY way you need to.
Here's the new tip: Rounding Numbers in Access
Enjoy!
Richard
P.S. Stay tuned for more videos coming VERY soon. |
sheraz on 2/15/2009: Best site for new and Advance users
|
Greg Beben on 3/23/2009: You say that, to round up to the next integer: "I would use INT(x)+1. This will use the INT function to bring your value DOWN to the nearest integer. Then just add 1 to it." The problem with this solution is that it rounds an integer up to the next integer also. E.g. 4 becomes 5. Not sure if the person meant this, but suppose you want to round anything up if it's MORE THAN the plain integer? E.g. 4 stays 4, but 4.1 becomes 5. For example, if there are 50 envelopes in a box and I need 200, then 4 boxes is right. But if I need 210, then when I divide and get 4.2 boxes, I need to order 5. Can we do this?
|
Richard Rost on 3/23/2009: Greg, GOOD CATCH. I didn't think of that. You're right. INT(4)+1 will result in a 4 if the number is 4.0. So we're going to have to check and see if the number has any kind of a fractional component first. I'll add another field:
X: IIf(N<>I,I+1,N)
N is the original number I is the INT(N)
Now, IF N is not I (in other words, N has a fractional component so it's different from I) then set X equal to I+1 (round it up) otherwise, it's just N (the original number).
Again, real good catch. I only tested my results with fractional numbers, not whole numbers.
Now about the problem you're having, you could just say:
B: N/50
This will yield 4.02 if N is 201, or 3.98 if N is 199. Now say:
Boxes: IIf(Int(B)=B,B,Int(B)+1)
Basically if the INT(B) is the same as N/50, then there is no fractional component (200, 150, etc.) so just use B. If there is a fraction, add 1 for one more box.
Same concept... and again, GREAT catch.
|
J on 7/28/2010: I'm working on a building a export file of Portfolio Holdings that will be imported into a system that can only take whole integers.
The access database I’m pulling from stores and calculated the individual holdings weighting based on home many securities are selected to be held.
ex. 25% of the portfolio is allocated among 4 securities. 25/4 = 6.25 per security. Or this could change to 25% allocated among 3 securities…25/3=8.33 (realistically N securities) Problem arises when I round. If all are rounded down, 8+8+8=24 not 25. At the end of the day I need various groups of 25%(any size group, with any # of holdings within the group) to add up to 100%.
Any Ideas?
Reply from Richard Rost:
You would have to perform the math, rounding down. Then, when you're done, check the sum of the parts, and if they don't add up, add 1 to the first (or last) item in the group.
|
Aaitaman on 7/23/2011: I have unbound textbox where i used =[Safe]/[Obser]to get total percent and i got the total percent but have two extra digits. i used this =Round ([Safe]/[Obser],0) as well to rid of those two extra digit but did not fix my problems Example i am having this now 100.00%, i wan this way 100% Any help?
|
Alex Hedley on 7/23/2011: Hi Aaitaman,
Click on the textbox then open the Property Sheet. Now on the Format tab make sure the Format is Percent and the Decimal Places is 0
Al
|
|
|
| |
|
You may want to read these articles from the 599CD News: |
|
|
|