Solved

Round Function

Posted on 2003-11-06
2
2,251 Views
Last Modified: 2010-05-18
I am trying to round some numbers..while 159.975 is rounding properly, 159.965 isnt.
Shouldn't VB always round up on the 5? It seems to only do it when the digit preceding
it is an odd number.

Round("159.965", 2)     ' RETURNS "159.96"  
Round("159.975", 2)     ' RETURNS "159.98"    

I tried the same thing with FormatCurrency and it works as I expect however I don't
want the dollar sign in front. It's a simple matter to strip the dollar sign with the Replace
function but would like an explanation about why the Round function behaves that way.
Is there a more elegant approach than stripping the '$' sign and using FormatCurrency?

Thanks
0
Comment
Question by:const71
2 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 30 total points
ID: 9697862
this is a STANDARD rounding procedure for VB.  It is known as "Banker's Rounding", and is discussed at length at

http://support.microsoft.com/default.aspx?scid=kb;EN-US;196652

AW


0
 

Author Comment

by:const71
ID: 9698162
yes but the two methods i showed you provide 2 different ways of rounding. I'll read the article and see what it says...


thanks

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 121
Excel VBA combine two working workbooks 8 56
Copy a row 12 62
Passing a Text Box name to a Sub 6 96
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question