Consulting

Results 1 to 6 of 6

Thread: Solved: Is It "Round" or "Application.Round"??

  1. #1

    Solved: Is It "Round" or "Application.Round"??

    I was just modifying some old code and I noticed that some of the macros I had used "Round" and others I had used "Application.Round". Both forms seem to work OK. Is there some subtle difference between the two?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    They use different rounding algorithms, which you should undedrstand if using them. See

    http://support.microsoft.com/default.aspx?kbid=194983
    PRB: Round Function different in VBA 6 and Excel Spreadsheet

  3. #3
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Thus, if you see:

    [VBA]Debug.Print Round(x, 2)[/VBA]

    that is the VB/VBA function Round, which uses banker's rounding. If you see:

    [VBA]Debug.Print Application.Round(x, 2)
    Debug.Print Application.WorksheetFunction.Round(x, 2)[/VBA]

    you are using the Excel ROUND function, which always rounds up if the digit you're checking is >= 5.

    Patrick

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    FYI, Round is not supported in Excel 97, although the worksheetfunction version is if called upon in VBA.

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    xld, that is a GREAT reference on rounding. And it referred to an even better one. Arrrgh! Now I know why I used the spreadsheet Round. The Banker's round is an interesting technique, which I personally would never have a use for. However, in my youth as an engineer, I can look back and recall instances in which the Banker's round would have been more appropriate than the arithmetic round. Thanks to all of you for the informative response!

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The Banker's Round.
    On deposits they round down, on borrowing they round up. Or have I got it wrong?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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