424,968 Members | 1,588 Online
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

# Round numbers to integer

 P: n/a I am looking for a way to round down the results of a calculation in a query f.e.: in a query this calculation is performed: a/b = c 5/3 = 1,666666667 I would like this to be rounded to 1, the lower nearest integer. How would I do this in a query???? TIA HENRO Mar 19 '07 #1
10 Replies

 P: n/a Hi, I am looking for a way to round down the results of a calculation in a query f.e.: in a query this calculation is performed: a/b = c 5/3 = 1,666666667 I would like this to be rounded to 1, the lower nearest integer. How would I do this in a query???? You can use int or fix - e.g. int(5/3) To be aware of the differences of it take a look at the online help. Regards Jens Mar 19 '07 #2

 P: n/a On Mar 19, 7:26 am, "Henrootje"

 P: n/a IMHO, absolutely the best rounding function that I have ever seen. Option Compare Database 'Use database order for string comparisons Option Explicit Global Const vb_roundup = 1 Global Const vb_rounddown = 0 Function RoundToNearest(Amt As Double, RoundAmt As Variant, Direction As Integer) As Double On Error Resume Next Dim Temp As Double Temp = Amt / RoundAmt If Int(Temp) = Temp Then RoundToNearest = Amt Else If Direction = vb_rounddown Then Temp = Int(Temp) Else Temp = Int(Temp) + 1 End If RoundToNearest = Temp * RoundAmt End If End Function ======================== Usage: roundtonearest(5/3,1,1) Result:1 RoundToNearest(0.6723983761,.000005,0) Result: 0.672395 ======================== "Matt"

 P: n/a "Don Leverton"

 P: n/a On Mar 19, 10:13 pm, lyle fairfield

 P: n/a P.S., I noticed that my CDMA postings average a two star rating out of five. I noted that Lyle also has an average rating of two stars and I felt like I was in good company. After viewing the profiles of a few other regular posters I concluded that the stars seem to have worked out to be in proportion to how much we push MS products :-). Rated where, by whom, Jim? I'm probably going to be embarrassed when I find out and take a look... and not for the reason Lyle meant, if he meant what I thought he meant, which isn't necessarily the case. And, I agree with you that Lyle's posts are generally a "good read". And, hey, any guy who has a fondness for redheads can't be _ALL_ bad. Larry Mar 22 '07 #7