# round a number to the next highest number,regardless of value of reciprocal

dim x as single

if its x.0
i want it to stay x

if its x.1 - x.9 i want to to change to (x+1)

thanks!
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Will this work?

Private Sub Command1_Click()
x = 1.9
MsgBox Round(x + 0.4)
End Sub
0
Commented:
jxharding,
Add .5 to the value as you round it.

Dang123
0
Commented:

Dim x as Single
IF x - Abs ( x ) > 0 THEN
x = Abs ( x ) + 1
END IF
0
Commented:

Function FixIt(n As Single)
FixIt = n + IIf(n <> Int(n), (1 - (n - Int(n))), 0)
End Function
0
Commented:
try this:

msgbox Convert(5.0)
msgbox Convert(5.1)
...
msgbox Convert(5.9)

Private Function Convert(strVal As Single)
Convert = IIf((strVal * 10) \ 10 = strVal, strVal, Int(strVal + 1))
End Function

cheers,
srimanth.
0
Commented:
So that you get uniform results with negatives here is a simple but comprehensive function.

Hope this helps:~)

Function RoundToNext(psngNumeric As Single) As Single ' or whatevery type you need.

RoundToNext = Sgn(psngNumeric) * Int(Abs(psngNumeric) + 0.9999)

End Function
0
Commented:
Dim x As Single
Dim y() As Single
Dim z As Single

Private Sub Command1_Click()
x = Text1.Text
End Sub
If InStr(1, x, ".") Then
y() = Split(x, ".")
z = x - y(0)
x = x + (0.1 - z)
End If
MsgBox x
Exit Sub

that might work, I'm not at home right now so i can't test it...
0
Commented:
sorry.. got home and fixed it, should be:

Dim x As Single
Dim y() As String
Dim z As Single

Private Sub Command1_Click()
x = Text1.Text
If InStr(1, x, ".") Then
y() = Split(x, ".")
z = x - y(0)
x = x + (1 - z)
End If
MsgBox x
End Sub
0

Experts Exchange Solution brought to you by