|
-
Feb 4th, 2000, 06:31 AM
#1
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.
-
Feb 4th, 2000, 06:53 AM
#2
Hyperactive Member
What kind of rounding is that!
------------------
Ryan
-
Feb 4th, 2000, 07:24 AM
#3
Try this:
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
Usage:
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]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|