Results 1 to 3 of 3

Thread: Rounding up/down

  1. #1
    Guest

    Post

    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.

  2. #2
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    What kind of rounding is that!

    ------------------
    Ryan

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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
  •  



Click Here to Expand Forum to Full Width