471,119 Members | 1,272 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Decimal.Round lunacy

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
Jul 21 '05 #1
17 2482
This is actually pretty standard. Do a search on google for papers and
such....

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #2
Ooops.. Its called Banker's rounding
"NoOne" <No@Where.com> wrote in message
news:eN*************@TK2MSFTNGP09.phx.gbl...
This is actually pretty standard. Do a search on google for papers and
such....

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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


Jul 21 '05 #3
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

"NoOne" <No@Where.com> wrote in message
news:#k**************@TK2MSFTNGP10.phx.gbl...
Ooops.. Its called Banker's rounding
"NoOne" <No@Where.com> wrote in message
news:eN*************@TK2MSFTNGP09.phx.gbl...
This is actually pretty standard. Do a search on google for papers and
such....

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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



Jul 21 '05 #4
write your own method then.

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

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #5
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
"c# newbie" <no****@leave.me.alone> wrote in message
news:31******************************@news.teranew s.com...
write your own method then.

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

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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


Jul 21 '05 #6
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.
"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #7
William Ryan <do********@comcast.nospam.net> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
Rob Oldfield <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #9
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

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Rob Oldfield <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #10
....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
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Rob Oldfield <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #11
This isn't going to solve the problem for you, but it does provide
justification: http://tinyurl.com/vv4v

Colin

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #12
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
"Colin Young" <x@nospam.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl...
This isn't going to solve the problem for you, but it does provide
justification: http://tinyurl.com/vv4v

Colin

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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


Jul 21 '05 #13

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
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
Jul 21 '05 #14
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...b;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

Jul 21 '05 #15
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

"Matthew W. Jackson" <th********************@NOSPAM.NOSPAM> wrote in message
news:Oo**************@TK2MSFTNGP11.phx.gbl...
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...b;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

Jul 21 '05 #16
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
"Kevin Gale" <kg***@PLEASE-DELETEprintcafe.com> wrote in message
news:10*************@mail1.segnet.com...

"Rob Oldfield" <r$ob@oldfi$eld100.freese$rve.c$o.uk> wrote in message
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

Jul 21 '05 #17

"Rob Oldfield" <rob@oldfield100_wow_freeserve_yikes_co_incredible !_uk> wrote in
message news:uV**************@TK2MSFTNGP11.phx.gbl...
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
Jul 21 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.