Decimal.Round lunacy

R

Rob Oldfield

From the documentation about Decimal.Round....

"When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position. For
example, when rounded to two decimals, the value 2.345 becomes 2.34 and the
value 2.355 becomes 2.36. This process is known as rounding toward even, or
rounding to nearest."

I'd have to disagree. I'd go for something more like "This process is known
is arbitrarily ignoring a de facto standard." Does anyone have a sensible
method of returning the correct rounded value i.e. without resorting to
decimal.round(x+0.00000001,2)

And has anyone got any justification for this ludicrousness?
 
R

Rob Oldfield

I repeat. It's lunacy. It might be a good idea, but the fact is that
NOBODY ACTUALLY DOES IT THIS WAY.

Well, that might be an exaggeration, but very few people.
 
C

c# newbie

write your own method then.

make an enum of values ( like odd, even digits )
and make up a rule.
 
R

Rob Oldfield

I could do that, yes. The reason for the question is with the hope that
somebody else has already done it and would be willing to share their code.

I still say that it's ludicrous that MS didn't get it right to start off
with. Would it be OK if the '+' operator worked perfectly except on
Tuesday's. Perfectly simple to replace function add(x,y) with....

dim newY
if day=tuesday
newY=y*-1
add=x-y
else
add=x+y
end if

....but still monumentally stupid.
 
W

William Ryan

MS has a reason for doing it, but you're not alone in your frustration, b/c
many don't realize it until after it's too late. At least an overload
should have been provided so you can use either method IMHO.
 
J

Jon Skeet [C# MVP]

William Ryan said:
MS has a reason for doing it, but you're not alone in your frustration, b/c
many don't realize it until after it's too late. At least an overload
should have been provided so you can use either method IMHO.

Rather than an overload, there should be an enumeration of rounding
types, or possibly something like the Encoding hierarchy.
 
J

Jon Skeet [C# MVP]

Rob Oldfield said:
I repeat. It's lunacy. It might be a good idea, but the fact is that
NOBODY ACTUALLY DOES IT THIS WAY.

Well, that might be an exaggeration, but very few people.

I suspect that decimal is generally intended for financial
applications, and given that the name is "banker's rounding" my guess
is that it's not uncommon in that sector. I don't personally have a lot
of experience with the financial sector - do you?
 
R

Rob Oldfield

The app that I'm writing that this error has just come up is for an
investment house. When I told their accounts manager that this was the
problem his reaction was "That's absolutely ludicrous. I've never heard of
anyone doing it that way."

This is in the UK though, it may be that things are different in the US, but
certainly 'rounding' over here is 100% 'round halves upwards'.
 
R

Rob Oldfield

....and something else I didn't think of in my previous answer....

The vast majority of bankers thoughout the world are using Excel. The round
function in Excel works on the 'round halves up' method. Either they all
know about the difference between their hand-crafted figures and the central
office system and they've given themselves a way around it, or there are a
lot of pennies going missing somewhere.

Next question: can you think of a way of funnelling all these pennies into
an account that I'll set up tomorrow?
 
R

Rob Oldfield

Thanks for that. I get the justification and it does indeed make sense (in
much the same way that the optimal keyboard layout as opposed to QWERTY),
but the problem is if nobody in the real world actually uses it. As I've
said elsewhere in this thread, it may be that US bankers do, but UK ones
certainly don't.

I'd also say that it's not the way that the function works that is the
problem but, as Jon and William point out, that there isn't a sensibly
accessible method of choosing what method to use.
 
K

Kevin Gale

Rob Oldfield said:
And has anyone got any justification for this ludicrousness?

It's not any more ludicrous than deciding that x.5 always rounds up when
it is in fact equally close to the value below it. In fact it is statistically
much
better to sometimes round up and sometimes round down in that case.

Both methods have their place.
I like Jon's idea. There should be an enumeration of rounding types.

-- Kevin Gale
 
M

Matthew W. Jackson

I always found it VERY odd that Excel used Arithmetic rounding (.5 rounds
up), where as VBA (which is integrated into Excel), and therefore
VisualBasic 6, use Banker's rounding.

If you think Banker's rounding is "lunacy", then you probably have never
done any work in statistics. Using arithmetic rounding is asymmetric, and
can skew data. Very bad....

This page explains rounding and how Excel rounds in various cases.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;196652

Read down on the page, and it describes the reasoning. Here's an excerpt:

"When you add rounded values together, always rounding .5 in the same
direction results in a bias that grows with the more numbers you add
together. One way to minimize the bias is with banker's rounding.

Banker's rounding rounds .5 up sometimes and down sometimes. The convention
is to round to the nearest even number, so that both 1.5 and 2.5 round to 2,
and 3.5 and 4.5 both round to 4. Banker's rounding is symmetric."

In fact, in any statistics project I did in college, we were required to use
either Banker's rounding or Random rounding. I was annoyed to find that I
had to implement my own rounding function in Excel to do Banker's rounding.
Go figure.

--Matthew W. Jackson
 
R

Rob Oldfield

For what it's worth, I never meant to imply that I thought the method of
banker's rounding was lunatic. What I _did_ mean was that Microsoft's
decision to arbitratily impose one method, and to choose a non-standard one,
was lunatic.
 
R

Rob Oldfield

Always rounding up may be ludicrous, but the point is that it's a standard
ludicrous.
 
K

Kevin Gale

Rob Oldfield said:
Always rounding up may be ludicrous, but the point is that it's a standard
ludicrous.

Standard for who? Microsoft does it both ways in different products and Borland
uses banker's rounding in most of it's products but has a few exceptions. I'm
positive that a little research would come up the lots of products that do it
one way and lots the other. Seems like the problem is that there is no standard
(although I'm told that the IEEE 754 floating-point standard does specify
banker's rounding).

I agree with you in the sense that it should be a standard one way or the other.
Having it change from one product to another is just asking for trouble.

-- Kevin
 

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

Similar Threads

Rounding, are we MAD???? 8

Top