Rounding, are we MAD????

G

Guest

Howcome:

Dim D as decimal = .5D
msgbox d.Round(D, 0)

this returns "0"

Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!!

Documentation says this, but what the heck are they thinking??? I just don't
get it. This is insane!?!?!?!! (or maybe I am)

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

Guest

It's actually the BANKERS fault:

"The behavior of this method follows IEEE Standard 754, section 4. This kind
of rounding is sometimes called rounding to nearest, or banker's rounding."

Anyway, the reason this all came up was because we were doing some
compairson between some old ACCESS reports and some new reports we are
designing in VB.NET. In ACCESS, when a value of .05 was FORMATTED "0,0" it
returned 0.1, which goes along with my third grade math thinking. When we
changed the formula to use the ROUND function, it returned 0. An odd and
obscure little gotcha that we just stumbled across, I guess.

Oh well, that was fun...!
 
G

Guest

Zorpie,

Rounding in .Net at least claims to follow IEEE Standard 754. Therefore,
several different ways to round are provided:

Round
Ceiling
Floor

In addition, VB provides several keywords that apply to rounding in one way
or another:

INT
FIX
CINT

You just need to pick a method or keyword that works the way you need it to
for a particular application.

Kerry Moorman
 
G

Guest

Zorpie,

I suspect that Simple Math, Grade 3 does not comform to IEEE Standard 754
with respect to rounding because IEEE Standard 754 is too complex for third
graders.

If you want to always use the type of rounding you learned in third grade,
then Math.Ceiling might be for you.

Kerry Moorman
 
N

Norman Diamond

It's actually the BANKERS fault:

"The behavior of this method follows IEEE Standard 754, section 4. This
kind of rounding is sometimes called rounding to nearest, or banker's
rounding."

Funny. When I learned it in grade 9 it had nothing to do with banking or
engineering, it was just math (yes grade 9 math was more complicated than
grade 3 math, just like calculus is more complicated than grade 3 math). In
university I learned why engineers had better make sure to do rounding this
way, coding it themselves if the hardware didn't do it for them. From your
posting I learn that bankers find it equally important.

But it's still not the fault of bankers or engineers or mathematicians. If
you believe in Intelligent Design then it's God's fault. As for your
trouble with grade 9 math, whose fault is that? I do agree with one of your
observations though. When Microsoft graduated from grade 3 to grade 9, it
was a breaking change.
 
C

Cor Ligthert [MVP]

Zorpiedoman,

This is one of the changes in VS 2005, it allows more kind of roundings.

Cor
 
G

gjuro kladaric

so, nobody answered the question "is this rounding expected and declared to
produce 0 from .5 ?". do IEEE rules commands this?
 
C

Cor Ligthert [MVP]

Gjuro,
produce 0 from .5 ?". do IEEE rules commands this?

Yes as already probably thousand times answered in these newsgroups,

However in my opinon should any good develloper be able to set the rounding
in the style he wishes by creating the code for that himself, if it is not
provided as a standard.

Cor
 

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

Top