Can anyone help Me for this Problem

A

Arvind Mane

Please go through the following excel Macro

Sub Arvind()
a = 1.845
b = Round(a, 2)
End Sub


i want "b" value as 1.85 but the macro is giving me 1.84.
What can i do for this ?
 
S

Sheeloo

Following is taken from http://www.techonthenet.com/excel/formulas/round.php

In Excel's VBA environment, the Round function returns a number rounded to a
specified number of decimal places. However, the Round function behaves a
little peculiar, so before using this function, please read the following:

The Round function utilizes round-to-even logic. If the expression that you
are rounding ends with a 5, the Round function will round the expression so
that the last digit is an even number. For example:

Round(12.55, 1) would return 12.6 (rounds up)
Round(12.65, 1) would return 12.6 (rounds down)
Round(12.75, 1) would return 12.8 (rounds up)

In these cases, the last digit after rounding is always an even number. So,
be sure to only use the Round function if this is your desired result.

Acknowledgements: A special thanks to Mary S.
 
D

Dana DeLouis

i want "b" value as 1.85 but the macro is giving me 1.84.
What can i do for this ?

Hi. I believe the vba version uses the Round-to-even method
http://en.wikipedia.org/wiki/Rounding

Seems like the help system in Excel 2007 dropped some of this information.

Sub Arvind()
Dim a, b
a = 1.845
b = Round(a, 2)
b = WorksheetFunction.Round(a, 2)
End Sub

--
Dana DeLouis
 

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