Rounding 0.5 to 1
VBA's Round() method rounds a 5 in the last digit to the next EVEN
number (which is pretty standard in scientific and financial
calculations, rather than XL's method that biases results away from
zero). So 0.5 rounds to 0, 1.5 rounds to 2, 2.5 rounds to 2, 3.5 rounds
to 4, etc...
However, you can use XL's function:
Public Sub rwnd()
Dim c As Double
c = 0.5
MsgBox Application.Round(c, 0)
End Sub
In article ,
"rd" wrote:
I wonder why my VBA code is not rounding 0.5 to 1. The code below produces
zero in the message box instead of the required 1.
Public Sub rwnd()
c = 0.5
MsgBox Round(c, 0)
End Sub
Any help would be appreciated.
|