Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Round Function

Posted on 2003-11-06
2
2,252 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 44
Exit a vb6 apps when a calling it apps closes 15 52
Collapse and expand table in Word 2010 2 32
Set WorkSheet  not Working 9 39
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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