Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding Of Numbers

Status
Not open for further replies.

drewduncan

Programmer
Apr 3, 2003
38
0
0
GB
Hope someone can be of help,

Does anyone know how to round ALL decimal numbers up to the nxt whole number e.g. 1.1 would be 2, 2.3 would be 3 and so on.

Any feedback would be greatly appreciated.

Cheers

Drew.
 
Hi Drew!

Assuming the users are inputting the number via a text box you can use the following code:

Dim lngRoundUp As Long
Dim lngPosition As Long

lngPosition = InStr(YourTextBox.Value, ".")

If lngPosition <> 0 then
lngRoundUp = Clng(Left(YourTextBox.Value, lngPosition - 1) + 1)
Else
lngRoundUp = Clng(YourTextBox.Value)
End If

I have assumed that you do not want to add one to the value in the text box if it isn't a decimal.

hth


Jeff Bridgham
bridgham@purdue.edu
 
let access round for you.

Dim x As Long
x = InputBox(&quot;enter&quot;)
Dim y As Integer
y = x
If y > x Then
MsgBox (y)
ElseIf y < x Then
y = y + 1
MsgBox (y)
Else
MsgBox (y)
End If

check that out.

it can be trimmed down, but put that on a button click or something click... it's just a quick example of how to do rounding using an integer without using anything fancy.



Randall Vollen
National City Bank Corp.

Just because you have an answer - doesn't mean it's the best answer.
 
This should work....
Code:
=Abs((Int([YourNumber]*-1)))


Hoc nomen meum verum non est.
 
Why not use the Fix function.

Rounded = Fix(NumericValue) + 1

Do Note the behavior of Fix with negative numbers.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
This method has a problem with whole numbers:
Code:
 Fix(5) + 1 = 6

Hoc nomen meum verum non est.
 
true - good point

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top