Incorrect ROUND function - MS Access 2000/XP?

L

Ludi

If I let run this little procedure in MS Access 2000 or XP, I get surprising
results.

Private Sub xy()
MsgBox Round(1.5, 0) ; -> 2
MsgBox Round(2.5, 0) ; -> 2
MsgBox Round(3.5, 0) ; -> 4
End Sub

I would say: round(2.5, 0) is 3 and not 2.
MS Excel has the same opinion as I, it says 3.
Why does ACCESS have here another opinion?
 
G

George Nicholson

http://support.microsoft.com/default.aspx?scid=kb;en-us;225330
OFF2000: New Round Function in Visual Basic for Applications 6.0

When the Round decimal-place argument is zero:
Excel rounds all values of .5 up to the next whole number.

VB rounds odd integers + .5 up
and even integers + .5 down (i.e, 2.5, 4.5, 6.5, etc, would all be rounded
down)

The article tells you how to use Excel's worksheet function within VB code
if you desire the consistency.

HTH,
 
L

Ludi

Hello George, thank you for your answer.

Now I wrote this function:
Public Function SE_Runden(zahl As Double) As Long
Dim appExcel As Object
Set appExcel = CreateObject("Excel.Application")
SE_Runden = appExcel.WorksheetFunction.Round(zahl, 0)
Set appExcel = Nothing
end function

It works correctly, but I have to use this function in a query and because
of the connection to Excel it is very slow.

Is there a possibility to make it faster.
Is there a special reason, why Access and Excel round differently?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top