473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Round numbers to integer

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 4613
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
On Mar 19, 7:26 am, "Henrootje" <Hen...@gmail.comwrote:
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


Something else you could do is 5\3 (Slash in the opposite direction).

Options!!!

Mar 19 '07 #3
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" <md*******@yahoo.comwrote in message
news:11**********************@l75g2000hse.googlegr oups.com...
On Mar 19, 7:26 am, "Henrootje" <Hen...@gmail.comwrote:
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

Something else you could do is 5\3 (Slash in the opposite direction).

Options!!!

Mar 20 '07 #4
"Don Leverton" <le****************@telusplanet.netwrote in
news:1cHLh.64305$lY6.48607@edtnps90:
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
How many others have you seen?

Wouldn't it be great to have a function that could round verbose
functions down to one line?

I guess I'm not so hot at math ... let's see ... 5/3 rounded up ... to
the nearest integer (maybe that's not what that means ... what does
RoundAmt mean anyhow? and why is it a variant? ... did you mean
deviant?)... is one? Hmmmmmmm! Guess the old mind is just not working
tonight, not to mention .... Sorry, Larry, didn'tmean to embarass you
there.
Mar 20 '07 #5
On Mar 19, 10:13 pm, lyle fairfield <lylef...@yahoo.cawrote:
"Don Leverton" <leveriteNoJunkM...@telusplanet.netwrote innews:1cHLh.64305$lY6.48607@edtnps90:


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

How many others have you seen?

Wouldn't it be great to have a function that could round verbose
functions down to one line?

I guess I'm not so hot at math ... let's see ... 5/3 rounded up ... to
the nearest integer (maybe that's not what that means ... what does
RoundAmt mean anyhow? and why is it a variant? ... did you mean
deviant?)... is one? Hmmmmmmm! Guess the old mind is just not working
tonight, not to mention .... Sorry, Larry, didn'tmean to embarass you
there.- Hide quoted text -
I still haven't stopped laughing. Since you asked for a one-
liner :-),

Function RoundToNearest(NearestAmt As Double, ValueToRound As Double,
Direction As String) As Double
RoundToNearest = IIf(Direction = "Up", -NearestAmt * Int(-
ValueToRound / NearestAmt), NearestAmt * Int(ValueToRound /
NearestAmt))
End Function

Example:

RoundToNearest(1, 5 / 3, "Up") =2
RoundToNearest(1, 5 / 3, "Down") =1
RoundToNearest(15, -1, "Down") =-15

The basic ideas are outlined in:
http://groups.google.com/group/micro...14be58d0485dd0

but test before using anyway. Note that it does not round verbose
functions down to one line as Lyle requested.

James A. Fortune
CD********@FortuneJames.com

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 :-).
Mar 20 '07 #6
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
Hi, Larry.
Rated where
Google Groups. Please see the following Web pages for the average rating on
a few Google profiles:

James's:

http://groups.google.com/groups/prof...JdoyCsxg&hl=en

Lyle's:

http://groups.google.com/groups/prof...5IG9SZ-Q&hl=en

Yours:

http://groups.google.com/groups/prof...QNTOMjnQ&hl=en
by whom
By anyone with a Google Groups account who cares to rate a poster's answer
so that future newsgroup archive researchers will know whether or not a post
is worth reading. It's anonymous and completely subjective, so until lots
of people rate posts over a long period of time, one must take an individual
rating with a grain of salt. It's rather like Amazon.com, where if a new
book has only one review from a reviewer who panned it, one can't take that
as Gospel that it's a crappy book. However, if there are four or more
reviews from different people and they all gave it only one star, then it's
fairly obvious that the book isn't worth buying.
I'm probably going to be embarrassed when I find out and take a look
Don't be. Almost none of the Access MVP's are aware of the publicly
available tools to rate their answers. Since it's subjective and hardly
anyone is using Google's rating system yet, and it's fairly new, the numbers
can be pretty skewed. As always, the few complainers cry out far louder
than the satisfied customers who give pats on the back, even if the
satisfied customers outnumber the complainers 10 (or more) to 1.
And, I agree with you that Lyle's posts are generally a "good read".
I'm sure if everyone took the time to rate his answers, he'd have mostly
five stars. For all we know, it could be one disgruntled poster marking the
handful of Lyle's answers with two stars as "below average" because he
didn't like Lyle's attitude -- or because he hates all redheads and people
fond of redheads.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
"Larry Linson" <bo*****@localhost.notwrote in message
news:RooMh.12547$e47.7878@trnddc05...
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 #8
Thanks, Gunny. I am, it turns out, not embarrassed, but pleasantly
surprised, at how well my posts are rated.

Larry
Mar 22 '07 #9
On Mar 22, 4:24 pm, "Larry Linson" <boun...@localhost.notwrote:
Thanks, Gunny. I am, it turns out, not embarrassed, but pleasantly
surprised, at how well my posts are rated.

Larry
Larry,

http://groups.google.com/group/comp....s-access/about

shows that with 12404 postings to CDMA you have the most all time
postings to this NG.

James A. Fortune
CD********@FortuneJames.com

Main email addresses I've used to post:

ja******@oakland.edu (out of service)
ji********@compumarc.com (out of service)
CD********@FortuneJames.com
MP*******@FortuneJames.com

Mar 23 '07 #10
<CD********@FortuneJames.comwrote
http://groups.google.com/group/comp....s-access/about

shows that with 12404 postings to CDMA you have the most all time
postings to this NG.
That's not nearly all of my posts... just under one e-mail (that I haven't
used in almost 3 years).

Larry
Mar 23 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Russell E. Owen | last post by:
I realize this probably a stupid question, but...is it safe to round to the nearest integer by using int(round(val))? I suspect it is fine, but wanted to be sure that weird floating point...
6
by: Jef Driesen | last post by:
I need to implement a function to implement the rounding of floating point values. At the moment i have two different implementations, depending on the type of the return value (integer or double)....
14
by: Nils Grimsmo | last post by:
Why did round() change in Python 2.4? $ python2.3 Python 2.3.5 (#2, Jun 19 2005, 13:28:00) on linux2 >>> round(0.0225, 3) 0.023 >>> "%.3f" % round(0.0225, 3) '0.023' >>>
3
by: shank | last post by:
I have the following equation. <% varWT = Round(CInt((rsFreePack.Fields.Item("Weight").Value)) + CInt(Session("w"))) %> Assume.... Round(CInt((rsFreePack.Fields.Item("Weight").Value)) = .12...
10
by: tmeister | last post by:
I'm trying to determine the best approach for rounding in an application I'm building. Unfortunately it appears as though SQL Server and VB.NET round in different ways. SQL Server select...
9
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something...
4
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal =...
1
by: Richard Cranium | last post by:
Using the number 1.015 ***************************** the following script returns 1.02, which is correct var T; var S=new String(Math.round(parseFloat(1.015).toFixed(2)*100)); while...
3
by: Aussie Rules | last post by:
Hi, Whats the easiest way to round numbers up. For example, a calculation that results in a value of 1.3 will round to 1, and a calculation that results in 1.8 will round to 2. My issue...
9
by: josh logan | last post by:
Hello, I need a round function that _always_ rounds to the higher integer if the argument is equidistant between two integers. In Python 3.0, this is not the advertised behavior of the built-in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.