Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Kansas, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rounding in a function (A2000)

    How would I round this expression to 2 decimal places? fMatch = ((curYTDE + curCE) * 0.03) - curYTDM

  2. #2
    yamafopa
    Guest

    Re: Rounding in a function (A2000)

    I don't know if this is the best way to do this, but this a way that works for me.

    I multiply by 100, then cast the double into a long integer using CLngo truncating the remaining decimal places, then divide by 100.


    CLng((((curYTDE + curCE) * 0.03) - curYTDM)*100)/100


    HTH
    Chris

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Kansas, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rounding in a function (A2000)

    Thanks Chris, that works for me, too.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Rounding in a function (A2000)

    I don't think using CLng will work. I would use the function below as follows:

    fMatch = gfRound2( ((curYTDE + curCE) * 0.03) - curYTDM)

    However, you might want to round prior to the subtraction, depending on your situation.

    <pre>Public Function gfRound2(ByRef RawData) As Currency
    ' This function rounds the "RawData" input to 2 decimal places.
    gfRound2 = CCur(CCur(RawData) / 100) * 100
    End Function
    </pre>

    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Rounding in a function (A2000)

    Try this:

    fMatch = Round(((curYTDE + curCE) * 0.03) - curYTDM,2)

    There wasn't a built-in round function in earlier versions, but there is in 2000. Just be aware that it doesn't work like the Excel rounding functions. This one only rounds up if the determinant is greater than 5.
    Charlotte

  6. #6
    Star Lounger
    Join Date
    Jan 2001
    Location
    Kansas, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for Round function

    Thanks, Charlotte, that was what I was looking for!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •