J
jan
I went to the Microsoft Knowledge base to try to get the
round up function and they gave me this code. I have used
this to round up but it is giving me one error.
Here is the code.
Function RoundToNearest(dblNumber As Double,
varRoundAmount As Double, _
Optional varUp As Variant) As Double
Dim dblTemp As Double
Dim lngTemp As Long
dblTemp = dblNumber / varRoundAmount
lngTemp = CLng(dblTemp)
If lngTemp = dblTemp Then
RoundToNearest = dblNumber
Else
If IsMissing(varUp) Then
' round down
dblTemp = lngTemp
Else
' round up
dblTemp = lngTemp + 1
End If
RoundToNearest = dblTemp * varRoundAmount
End If
End Function
My problem is that when it round up the number 201.5 it
round it to 203. This really messes other calculations.
Does anyone know how to fix this.
round up function and they gave me this code. I have used
this to round up but it is giving me one error.
Here is the code.
Function RoundToNearest(dblNumber As Double,
varRoundAmount As Double, _
Optional varUp As Variant) As Double
Dim dblTemp As Double
Dim lngTemp As Long
dblTemp = dblNumber / varRoundAmount
lngTemp = CLng(dblTemp)
If lngTemp = dblTemp Then
RoundToNearest = dblNumber
Else
If IsMissing(varUp) Then
' round down
dblTemp = lngTemp
Else
' round up
dblTemp = lngTemp + 1
End If
RoundToNearest = dblTemp * varRoundAmount
End If
End Function
My problem is that when it round up the number 201.5 it
round it to 203. This really messes other calculations.
Does anyone know how to fix this.