jxharding
asked on
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!
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!
jxharding,
Add .5 to the value as you round it.
Dang123
Add .5 to the value as you round it.
Dang123
Dim x as Single
IF x - Abs ( x ) > 0 THEN
x = Abs ( x ) + 1
END IF
Function FixIt(n As Single)
FixIt = n + IIf(n <> Int(n), (1 - (n - Int(n))), 0)
End Function
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.
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.
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
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
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...
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...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub Command1_Click()
x = 1.9
MsgBox Round(x + 0.4)
End Sub