iamedwardkim
IS-IT--Management
Is there an easy way to round numbers up to the nearest hundredth (e.g. 7.83942 and 7.83021 would both be rounded up to 7.84)? Thanks in advance.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function basRndUp2(MyVal As Double, RndVal As Single) As Double
'Michael Red 11/25/02
'Sample Usage
'? basRndUp2(7.83942, 0.01)
' 7.84
'? basRndUp2(7.83021 , 0.01)
' 7.84
If (Round(MyVal, 2) = Round(MyVal + (RndVal / 2), 2)) Then
basRndUp2 = Round(MyVal, 2)
Else
basRndUp2 = Round(MyVal + (RndVal / 2), 2)
End If
End Function
Public Function basRnd2Val(ValIn As Single, Rnd2 As Single) As Single
'Michael Red 11/27/02 Tek-Tips thread701-414063
'? basRnd2Val(7.49, 3.625)
' 10.875
'? basRnd2Val(7.49, 3)
' 9
'? basRnd2Val(7.49, 0.01)
'7.5
Dim ModRmdr As Single
Dim ValPart() As String
Dim DecPart() As String
Dim Shift(2) As Integer
Dim MyVal As Long
Dim MyRnd As Long
Dim MyRtn As Long
ValPart = Split(Str(ValIn), ".")
DecPart = Split(Str(Rnd2), ".")
If (UBound(ValPart) > 0) Then
Shift(0) = Len(ValPart(1))
Else
Shift(0) = 0
End If
If (UBound(DecPart) > 0) Then
Shift(1) = Len(DecPart(1))
Else
Shift(1) = 0
End If
If (Shift(0) > Shift(1)) Then
Shift(2) = Shift(0)
Else
Shift(2) = Shift(1)
End If
MyVal = Val(ValIn) * (10 ^ Shift(2))
MyRnd = Val(Rnd2) * (10 ^ Shift(2))
MyRtn = MyVal - (MyVal Mod MyRnd) + MyRnd
basRnd2Val = MyRtn * 10 ^ (-1 * Shift(2))
End Function
[code]
MichaelRed
m.red@att.net
Searching for employment in all the wrong places