# roundup() function

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

Good afternoon

This code will work for you

Function Round2(x)
'
' Rounds a number to 2 decimal places
' Uses arithmetic rounding
'
Round2 = Int(x * 100 + 0.5) / 100
End Function

Best Regards

Maurice St-Cyr
Micro Systems Consultants, Inc.

I made one modification and the code. Thanks I will look at you code to try
to understand it.
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
lngTemp = Int(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