How can I round up/down any number to one of these- 0, 50, 100, 150,200,250,300?
This is difficult to explain so here is example- number 49 should be 0, 64 should be 50, 140 should be 100 and so on.
Printable View
How can I round up/down any number to one of these- 0, 50, 100, 150,200,250,300?
This is difficult to explain so here is example- number 49 should be 0, 64 should be 50, 140 should be 100 and so on.
What kind of rounding is that!
------------------
Ryan
Try this:
Usage:Code:Function RoundTo(ByVal vValue As Variant, ByVal Multiple As Long, Optional ByVal Up As Boolean = False) As Long
Dim lTemp As Long
lTemp = Int(vValue / Multiple) * Multiple
If Up Then
RoundTo = lTemp + IIf(vValue Mod Multiple < (Multiple / 2), 0, Multiple)
Else
RoundTo = lTemp + IIf(vValue Mod Multiple > (Multiple / 2), Multiple, 0)
End If
End Function
NewValue = RoundTo(OldValue, 50) - Rounds Down to the Nearest 50
NewValue = RoundTo(OldValue, 50, True) - Rounds Up to the Nearest 50
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]