Groups | Blog | Home
all groups > dotnet general > november 2003 >

dotnet general : Decimal.Round lunacy


NoOne
11/19/2003 3:34:43 PM
This is actually pretty standard. Do a search on google for papers and
such....

[quoted text, click to view]

NoOne
11/19/2003 3:36:48 PM
Ooops.. Its called Banker's rounding


[quoted text, click to view]

William Ryan
11/19/2003 5:06:01 PM
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.
[quoted text, click to view]

Rob Oldfield
11/19/2003 8:05:19 PM
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?

--
For real reply address, lose the cash
www.realuk.co.uk

Rob Oldfield
11/19/2003 8:57:36 PM
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.

--
For real reply address, lose the cash
www.realuk.co.uk

[quoted text, click to view]

c# newbie
11/19/2003 9:32:15 PM
write your own method then.

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

[quoted text, click to view]

Rob Oldfield
11/19/2003 9:55:23 PM
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.

--
For real reply address, lose the cash
www.realuk.co.uk


[quoted text, click to view]

Jon Skeet [C# MVP]
11/19/2003 10:10:22 PM
[quoted text, click to view]

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

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Jon Skeet [C# MVP]
11/19/2003 10:12:43 PM
[quoted text, click to view]

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?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Rob Oldfield
11/19/2003 10:30:22 PM
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'.

--
For real reply address, lose the cash
www.realuk.co.uk

[quoted text, click to view]

Rob Oldfield
11/19/2003 10:54:36 PM
....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?

--
For real reply address, lose the cash
www.realuk.co.uk


[quoted text, click to view]

Colin Young
11/20/2003 1:40:01 PM
This isn't going to solve the problem for you, but it does provide
justification: http://tinyurl.com/vv4v

Colin

[quoted text, click to view]

Rob Oldfield
11/20/2003 7:37:38 PM
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.

--
For real reply address, replace the _surprised_ bits with dots
www.realuk.co.uk


[quoted text, click to view]

Kevin Gale
11/21/2003 9:53:52 AM

[quoted text, click to view]

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

Matthew W. Jackson
11/22/2003 1:06:16 AM
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


Rob Oldfield
11/23/2003 9:53:24 PM
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.

--
For real reply address, replace the _surprised_ bits with dots
www.realuk.co.uk

[quoted text, click to view]

Rob Oldfield
11/23/2003 9:55:09 PM
Always rounding up may be ludicrous, but the point is that it's a standard
ludicrous.

--
For real reply address, replace the _surprised_ bits with dots
www.realuk.co.uk


[quoted text, click to view]

Kevin Gale
12/1/2003 2:47:42 PM

"Rob Oldfield" <rob@oldfield100_wow_freeserve_yikes_co_incredible!_uk> wrote in
message news:uVWbrwgsDHA.3492@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

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

AddThis Social Bookmark Button