A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

I need to always Round UP if greater than zero at all. HOW?



 
 
Thread Tools Display Modes
  #1  
Old March 8th, 2010, 07:44 PM posted to microsoft.public.access.queries
RP
external usenet poster
 
Posts: 33
Default I need to always Round UP if greater than zero at all. HOW?

I am in office 2007 Access DB -
I have quantities that are greater than Zero but the Round function will
round down to 0, if the number is not over .5 - how do I get it to ALWAYS
round UP to the next nearest whole number even if it's .00001?
  #2  
Old March 8th, 2010, 07:51 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default I need to always Round UP if greater than zero at all. HOW?

Try this --
IIF(Int([YourField])[YourField], Int([YourField])+1 , [YourField])

--
Build a little, test a little.


"RP" wrote:

I am in office 2007 Access DB -
I have quantities that are greater than Zero but the Round function will
round down to 0, if the number is not over .5 - how do I get it to ALWAYS
round UP to the next nearest whole number even if it's .00001?

  #3  
Old March 8th, 2010, 08:30 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default I need to always Round UP if greater than zero at all. HOW?

If the number is always positive then the expression
-Int(-[YourField])
will always round up to the next integer value.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

KARL DEWEY wrote:
Try this --
IIF(Int([YourField])[YourField], Int([YourField])+1 , [YourField])

  #4  
Old March 8th, 2010, 09:09 PM posted to microsoft.public.access.queries
Marco[_6_]
external usenet poster
 
Posts: 11
Default new messenger

Friends and friends around the world.
We are presenting the new messenger.
He will be in the commissioning by the friends that we indicate to use the
system.
Access the system by clicking the link below and register free.

You get something for using orkut?
You get something for using skype?
You gain something by using twiter?
You get algumaocisa for using facebook?

Enjoy this is your time!!

Sign up and join for free.


http://www.sqipcom.com/?ref=webempreendedor

http://stakeholder.sqipcom.com/user/webempreendedor



  #5  
Old March 8th, 2010, 11:51 PM posted to microsoft.public.access.queries
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default I need to always Round UP if greater than zero at all. HOW?

Using an idea posted by James Fortune recently the following will round away
from zero to any interval:

Public Function RoundFromZero(dblVal As Double, dblTo As Double) As Double

Dim intUpDown As Integer

If dblVal 0 Then
intUpDown = 1
Else
intUpDown = -1
End If

RoundFromZero = intUpDown * (Int(dblVal / (intUpDown * dblTo))) * dblTo

End Function

So in your case to round to the nearest integer:

RoundFromZero([TheNumber], 1)

Conversely this rounds towards zero:

Public Function RoundToZero(dblVal As Double, dblTo As Double) As Double

Dim intUpDown As Integer

If dblVal 0 Then
intUpDown = -1
Else
intUpDown = 1
End If

RoundToZero = intUpDown * (Int(dblVal / (intUpDown * dblTo))) * dblTo

End Function

and this rounds up or down, i.e. 'up' rounds negative numbers towards zero,
positive numbers away from zero, and 'down' rounds negative numbers away from
zero, positive numbers towards zero. By default it rounds up; to round down
pass 1 in to the function as the optional third argument:

Public Function RoundTo(dblVal As Double, dblTo As Double, Optional intUpDown
As Integer = -1) As Double

' rounds up by default.
' to round down pass 1 into function as
' optional UpDown argument
RoundTo = intUpDown * (Int(dblVal / (intUpDown * dblTo))) * dblTo

End Function

Ken Sheridan
Stafford, England

RP wrote:
I am in office 2007 Access DB -
I have quantities that are greater than Zero but the Round function will
round down to 0, if the number is not over .5 - how do I get it to ALWAYS
round UP to the next nearest whole number even if it's .00001?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201003/1

  #6  
Old March 9th, 2010, 09:05 PM posted to microsoft.public.access.queries
David W. Fenton
external usenet poster
 
Posts: 3,373
Default I need to always Round UP if greater than zero at all. HOW?

"KenSheridan via AccessMonster.com" u51882@uwe wrote in
news:a4b9481ebbd89@uwe:

Using an idea posted by James Fortune recently the following will
round away from zero to any interval:

Public Function RoundFromZero(dblVal As Double, _
dblTo As Double) As Double
Dim intUpDown As Integer

If dblVal 0 Then
intUpDown = 1
Else
intUpDown = -1
End If

RoundFromZero = intUpDown * (Int(dblVal / (intUpDown * dblTo)))
* dblTo

End Function


I would recommend against doing all the calculations in one go, as
that's where floating-point errors creep in. I would change this:

RoundFromZero = intUpDown * (Int(dblVal / (intUpDown * dblTo))) *
dblTo

....to this:

dblDenominator = intUpDown * dblTo
dblTestValue = dblVal / dblDenominator
RoundFromZero = intUpDown * IntUpDown * dblTo

....that approach is based on the principles outlined by Luke Chung
in his old article on writing your own rounding function, where he
recommended storing the result of any calculation in a variable of
known precision so that you don't compound floating-point
inaccuracies.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
  #7  
Old March 9th, 2010, 10:49 PM posted to microsoft.public.access.queries
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default I need to always Round UP if greater than zero at all. HOW?

I take the point, David, and will implement it, but I think it will need to
be:

dblDenominator = intUpDown * dblTo
intTestValue = Int(dblVal / dblDenominator)
RoundFromZero = intUpDown * intTestValue * dblTo

Ken Sheridan
Stafford, England

David W. Fenton wrote:
Using an idea posted by James Fortune recently the following will
round away from zero to any interval:

[quoted text clipped - 13 lines]

End Function


I would recommend against doing all the calculations in one go, as
that's where floating-point errors creep in. I would change this:

RoundFromZero = intUpDown * (Int(dblVal / (intUpDown * dblTo))) *
dblTo

...to this:

dblDenominator = intUpDown * dblTo
dblTestValue = dblVal / dblDenominator
RoundFromZero = intUpDown * IntUpDown * dblTo

...that approach is based on the principles outlined by Luke Chung
in his old article on writing your own rounding function, where he
recommended storing the result of any calculation in a variable of
known precision so that you don't compound floating-point
inaccuracies.


--
Message posted via http://www.accessmonster.com

  #8  
Old March 10th, 2010, 07:53 PM posted to microsoft.public.access.queries
David W. Fenton
external usenet poster
 
Posts: 3,373
Default I need to always Round UP if greater than zero at all. HOW?

"KenSheridan via AccessMonster.com" u51882@uwe wrote in
news:a4c550d14717f@uwe:

I take the point, David, and will implement it, but I think it
will need to be:

dblDenominator = intUpDown * dblTo
intTestValue = Int(dblVal / dblDenominator)
RoundFromZero = intUpDown * intTestValue * dblTo


Hmm. I forgot about the Int() function, and so, there really needs
to be another variable:

dblDenominator = intUpDown * dblTo
dblTestValue = dblVal / dblDenominator
intTestValue = Int(dblTestValue)
RoundFromZero = intUpDown * intTestValue * dblTo

That's based on the principle of storing a calculation result in a
variable with a fixed accuracy, and then only performing
calculations on the variable.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
  #9  
Old March 10th, 2010, 08:17 PM posted to microsoft.public.access.queries
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default I need to always Round UP if greater than zero at all. HOW?

Right, I'll do that. Appreciated as always.

Ken Sheridan
Stafford, England

David W. Fenton wrote:
I take the point, David, and will implement it, but I think it
will need to be:

dblDenominator = intUpDown * dblTo
intTestValue = Int(dblVal / dblDenominator)
RoundFromZero = intUpDown * intTestValue * dblTo


Hmm. I forgot about the Int() function, and so, there really needs
to be another variable:

dblDenominator = intUpDown * dblTo
dblTestValue = dblVal / dblDenominator
intTestValue = Int(dblTestValue)
RoundFromZero = intUpDown * intTestValue * dblTo

That's based on the principle of storing a calculation result in a
variable with a fixed accuracy, and then only performing
calculations on the variable.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201003/1

  #10  
Old March 12th, 2010, 04:45 AM posted to microsoft.public.access.queries
David W. Fenton
external usenet poster
 
Posts: 3,373
Default I need to always Round UP if greater than zero at all. HOW?

"KenSheridan via AccessMonster.com" u51882@uwe wrote in
news:a4d08e7debef2@uwe:

Appreciated as always.


As with so many things I post, they aren't original with me -- I'm
just passing on things I learned from people far smarter than I.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:35 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.