Exodus
Registered User.
- Local time
- Yesterday, 22:02
- Joined
- Dec 4, 2003
- Messages
- 317
I need to round numbers up to the nearest 50
IE
80 = 100
110 = 150
1 = 50
I'm using this code and am get mostly the desired results except some
80 = 150
What can I do to fix this.
Im calling it in a query like this
PadQty: RoundToNearest([Qty],50)
IE
80 = 100
110 = 150
1 = 50
I'm using this code and am get mostly the desired results except some
80 = 150
What can I do to fix this.
Im calling it in a query like this
PadQty: RoundToNearest([Qty],50)
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
' round up
dblTemp = lngTemp + 1
RoundToNearest = dblTemp * varRoundAmount
End If
End Function