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

R

RP

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?
 
K

KARL DEWEY

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

John Spencer

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
 
M

Marco

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
 
K

KenSheridan via AccessMonster.com

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
 
D

David W. Fenton

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.
 
K

KenSheridan via AccessMonster.com

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
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.
 
D

David W. Fenton

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.
 
K

KenSheridan via AccessMonster.com

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

Ken Sheridan
Stafford, England
 
D

David W. Fenton

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top