ROUNDING (?!) in EXCEL.VBA

G

G.P.N.L. c.v.a.

Given BASISHE = 595.00

Why does

Function TEST2(BASISHE As Single) As Single

TEST2 = VBA.Round(BASISHE * 155.85 / 152.46, 2)

(or
TEST2 = VBA.Round(BASISHE * 155.85, 2)
TEST2 = VBA.Round(TEST2 / 152.46, 2)
or
TEST2 = Round(BASISHE * 155.85, 2)
TEST2 = Round(TEST2 / 152.46, 2)
or
TEST2 = BASISHE * 155.85
TEST2 = TEST2 / 152.46
TEST2 = Round(TEST2 , 2)
)

End Function

give "608.229980468750000... as result ? (as well in Excel 2003 as in Excel
2007)
and - more important - how can I fix this ?

Thanks for helping.
Gilbert
 
J

Jim Cone

Gilbert,
Using Double as both data types instead of Single "fixes" it.
Double is the only data type allowed for a numeric value in a worksheet cell.
I assume that in the conversion (by Excel) from Single to Double something gets lost.
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware

..
..
..

"G.P.N.L. c.v.a." <[email protected]>
wrote in message
Given BASISHE = 595.00
Why does

Function TEST2(BASISHE As Single) As Single

TEST2 = VBA.Round(BASISHE * 155.85 / 152.46, 2)
(or
TEST2 = VBA.Round(BASISHE * 155.85, 2)
TEST2 = VBA.Round(TEST2 / 152.46, 2)
or
TEST2 = Round(BASISHE * 155.85, 2)
TEST2 = Round(TEST2 / 152.46, 2)
or
TEST2 = BASISHE * 155.85
TEST2 = TEST2 / 152.46
TEST2 = Round(TEST2 , 2)
)
End Function

give "608.229980468750000... as result ? (as well in Excel 2003 as in Excel
2007)
and - more important - how can I fix this ?
Thanks for helping.
Gilbert
 

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