G
Guest
I retrieve the following code from the ms website, but I have the following
problem i have is that when it does is in step where the Clng function is
being call is rounding up the number and the proble is that if I have a
number like 2.3597 my the result is 2.37 instead of 2.36. can someone
provide me how can I ovoid that.
Public Function Roundup(dblNumber As Double, varRoundAmount As Double, _
Optional varUp As Variant) As Double
Dim dblTemp As Double
Dim lngTemp As Long
Dim db1Temp2 As Double
dblTemp = dblNumber / varRoundAmount
db1Temp2 = Right(db1Temp, 1)
lngTemp = CLng(dblTemp)
If lngTemp = dblTemp Then
Roundup = dblNumber
Else
If IsMissing(varUp) Then
' round down
dblTemp = lngTemp
Else
' round up
dblTemp = lngTemp + 1
End If
Roundup = dblTemp * varRoundAmount
End If
End Function
problem i have is that when it does is in step where the Clng function is
being call is rounding up the number and the proble is that if I have a
number like 2.3597 my the result is 2.37 instead of 2.36. can someone
provide me how can I ovoid that.
Public Function Roundup(dblNumber As Double, varRoundAmount As Double, _
Optional varUp As Variant) As Double
Dim dblTemp As Double
Dim lngTemp As Long
Dim db1Temp2 As Double
dblTemp = dblNumber / varRoundAmount
db1Temp2 = Right(db1Temp, 1)
lngTemp = CLng(dblTemp)
If lngTemp = dblTemp Then
Roundup = dblNumber
Else
If IsMissing(varUp) Then
' round down
dblTemp = lngTemp
Else
' round up
dblTemp = lngTemp + 1
End If
Roundup = dblTemp * varRoundAmount
End If
End Function