A
alex.richardson
I want to round up to the next higher 1000. For example,
15,600 should be rounded to 16,000. When I use the
RoundToNearest function on the knowledgebase, 15,600 is
rounded to 17,000.
Code I'm using is shown below. In my query I'm
entering "RoundToNearest(Number,1000,up)". How can I
change the code or query to round up to the next higher
1000 in all cases?
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
15,600 should be rounded to 16,000. When I use the
RoundToNearest function on the knowledgebase, 15,600 is
rounded to 17,000.
Code I'm using is shown below. In my query I'm
entering "RoundToNearest(Number,1000,up)". How can I
change the code or query to round up to the next higher
1000 in all cases?
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