Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
rd rd is offline
external usenet poster
 
Posts: 6
Default Rounding 0.5 to 1

Hi,

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.

Regards,
RD


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
rd rd is offline
external usenet poster
 
Posts: 6
Default Rounding 0.5 to 1

Thanks a lot for your help.

RD

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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,


I wouldn't be so quick to include "scientific" calculations in there. I was
a practicing Civil Engineer for some 30 years and we never rounded numbers
ending in 5 that way. Perhaps "scientific" calculations in laboraties, where
I would guess heavy use of Statistics takes place, that might be the case;
but in the practical world of road and bridge design (the fields I worked
in), this wasn't the case at all.


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


You can also use the Format function which is the only VB function that
rounds in the "proper" way. In your example, you could do this instead...

MsgBox Format(c, "0")


Rick

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Rounding 0.5 to 1

In article ,
"Rick Rothstein \(MVP - VB\)"
wrote:

I wouldn't be so quick to include "scientific" calculations in there. I was
a practicing Civil Engineer for some 30 years and we never rounded numbers
ending in 5 that way. Perhaps "scientific" calculations in laboraties, where
I would guess heavy use of Statistics takes place, that might be the case;
but in the practical world of road and bridge design (the fields I worked
in), this wasn't the case at all.


Well, I've had careers in both science and engineering, and they are
definitely NOT the same thing.

If you never rounded to even in civil engineering, biasing your results
away from zero was not apparently not significant to your results.

I've used round-to-even since at least junior high school in any physics
or chemistry class I've taken. I used it in designing and analyzing rf
and nuclear signal processing instrumentation.

Round-to-even has been the ASTM and IEEE754 standard for decades, at
least partly due to it being unbiased and not susceptible to drift over
many iterations.

However, as with any data reduction method, one has to analyze the data
space. One can imagine a set for which the symmetric arithmetic (XL's)
method might be preferable, but for natural data, round-to-even nearly
always produces no more bias, and usually less, than the XL method.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 837
Default Rounding 0.5 to 1

I agree that rounding to even is best practice to avoid systematic biases in
rounded numbers. I know that it is specified by almost all standards bodies
that bother to specify a rounding method (including ASTM, and in its
corresponding binary form IEEE). I also know that MS and some other
programming houses call it "banker's rounding", but I have been unable to
find evidence that it has ever been a standard in banking or other financial
calculations. Can you point me in the right direction?

Jerry

"JE McGimpsey" wrote:

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...

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Rounding 0.5 to 1

In article ,
Jerry W. Lewis wrote:

but I have been unable to find evidence that it has ever been a
standard in banking or other financial calculations. Can you point
me in the right direction?


Not really. Back in the early 80's I did some programming for financial
institutions, and the round-to-even method was specified (while I'm sure
they wouldn't have minded rounding up their clients' payments, all those
pennies going back out in interest held them back...). When I inquired
of the department head, I was told that this was standard even back
before electronic calculation. However, the ASTM standard was
well-established by then, so it could have been based on that. Based on
the little research I've done, I suspect that rather than being standard
in financial transactions, round-to-even was *a* standard method.

I guess I've just understood round-to-even to be so superior to
symmetric arithmetic rounding (in most situations) for so long that I
may the victim of unintentional confirmation bias <g.

FWIW, the *only* references to the origin of the term "Banker's
Rounding" that I've ever found is "unknown".

And for a discussion of on uncertainty, rounding, and the evils of
significant digits, I found this amusingly written rant worth reading
again:

http://www.av8n.com/physics/uncertainty.htm
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ROUNDING FORMULA =ROUND(B12/$B$10,1) ROUNDING TO HIGH SunshineinFt.Myers[_2_] Excel Worksheet Functions 7 March 5th 09 06:41 PM
I need a formula with rounding up & rounding down to the nearest . Tony Kay Excel Worksheet Functions 3 May 29th 07 11:13 PM
Rounding Bud Excel Worksheet Functions 3 November 25th 05 02:33 AM
Rounding El_Melenero Excel Discussion (Misc queries) 0 November 23rd 05 08:06 PM
Worksheet rounding vs VBA rounding Simon Cleal Excel Programming 4 September 2nd 05 01:50 AM


All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"