View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Jerry W. Lewis Jerry W. Lewis is offline
external usenet poster
 
Posts: 837
Default VB Round( ) function

Rounding away 5 to produce an even number is the ASTM standard for
rounding. MS calls it "Bankers' rounding", though I have yet to see any
evidence that it is used in banking. I have also seen it called
"unbiased rounding" since it tends to equalize the number times you
round up vs. round down. It also corresponds to the IEEE standard for
rounding. Excel 2000 introduced a Round function, and it rounds in this
fashion.

Rounding away 5 to produce the next larger number is a simplified
version of the above rule, that most of us in the US were taught in
elementary school. It is a poor way to treat data, since it tends to
introduce rounding biases, but is specified by the USP (United States
Pharmacopoeia), the IRS (U.S. Internal Revenue Service), and by European
banking web sites for Euro conversions. This is the way that Excel's
worksheet ROUND function has always rounded.

Jerry

Ture Magnusson wrote:

Andrew,

Perhaps the standard for rounding is different in
different parts of the world? Back in school (here
in Sweden) I was tought to round to the mearest
EVEN number when the value is just in-between.

49,5 should be rounded to 50
50,5 should be rounded to 50
51,5 should be rounded to 52
52,5 should be rounded to 52
53,5 should be rounded to 54
...and so on.

VBA's ROUND function behaves this way, just the
way I want it to. VBA also works like this when
automatically converting from floting-point to integer
data types. See this example:

Sub Test()
Dim d As Double
Dim i As Integer

MsgBox Round(3.5,0) '4

MsgBox Round(234.5,0) '234

d = 49.5
i = d
MsgBox i '50

d = 52.5 '52
i = d
MsgBox i
End Sub


Excel's ROUND worksheet function always rounds
UP (or actually away from zero). You can use Excel's
rounding function in VBA, like this:

RoundFunc = Application.Round(Mark, 0)

Also, as Glenn told you, you should change the datatype
of the Mark parameter to Double.