View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Jerry W. Lewis Jerry W. Lewis is offline
external usenet poster
 
Posts: 837
Default Round doesnt work the way it is expected

Exact ties are rounded to have an even final rounded digit: that would be up
for 1.5 and down for 4.5.

Jerry

"Don Guillett" wrote:

Then why did 1.5 and 4.5 not round the same?

--
Don Guillett
SalesAid Software

"Ron Rosenfeld" wrote in message
...
On Wed, 20 Dec 2006 05:25:00 -0800, Carlo

wrote:

Hello all

i'm a little confused here. Hope somebody can help me.
With following code:
---------------------------------------------------------
Sub Whyyyyyyyyyyyyyyyyyy()
x = 1.5
For i = 1 To 4
Debug.Print "(" & x & " * " & i & ") = " & x * i & " == Round(" &
x
* i & ") = " & Round(x * i, 0)
Next i
End Sub
---------------------------------------------------------
VBA returns me:
------------------------
(1.5 * 1) = 1.5 == Round(1.5) = 2
(1.5 * 2) = 3 == Round(3) = 3
(1.5 * 3) = 4.5 == Round(4.5) = 4
(1.5 * 4) = 6 == Round(6) = 6
------------------------

Why is Round(1.5) = 2 and Round(4.5) = 4 ?????

I don't really get it!


Thanks for any help

Carlo


The VBA Round function uses what has been termed, for some unknown reason,
"banker's rounding". When a value is "on the margin -- e.g. n.5), the
value
will be rounded to the nearest even number. See
http://blogs.msdn.com/ericlippert/ar.../26/53107.aspx for
further
discussion.


--ron