View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Nick Hodge Nick Hodge is offline
external usenet poster
 
Posts: 1,173
Default Round doesnt work the way it is expected

Carlo

I suspect it is something to do with VBAs handling of the IEEE spec for
floating point arithmetic on binary machines...it is strange though and what
is even more frustrating this round works, as you have seen, different to
Excel's ROUND, different to Access's Round function, which uses bankers
rounding!

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Carlo" wrote in message
...
Hi Don,

yeah, application.round works fine.

Still strange though.....

thanks a lot

Carlo

"Don Guillett" wrote:

Interesting. My test did the same. Try

application.round(x*i,0)

--
Don Guillett
SalesAid Software

"Carlo" wrote in message
...
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