round up

B

Bob Barrows [MVP]

Peter said:
You could, but it wouldn't provide the functionality that he's asking
for. The round function is foolishly implemented in my opinion. It
rounds even numbers down, and odd numbers up. Where would it ever be
useful to round
22.5 to 22, and 21.5 to 22?
In financial situations. That's why it's called banker's rounding. It's
intended to avoid the over-enrichment of one party vs. another in financial
transactions involving rounding by randomizing which way the number in the
middle will be rounded. Sometimes the bank will get the extra penny,
sometimes the customer will get it. It would be unfair if one party or the
other always got the extra penny, wouldn't it?

Why is your definition the "correct" one? Rounding is defined as setting the
value of a number to the closest rounded result. By this definition, the
number ending in 5 cannot be rounded, since neither rounded result is closer
to 5 than the other. So why do you insist it's correct to always round down
(or up)? Why not use a method that results in half the numbers being
rounded down, and half being rounded up? The aggregate result will probably
be closer to the non-rounded aggregate result than if you chose to always
round the middle number up or down.

Bob Barrows
 
E

Evertjan.

=?Utf-8?B?am9lYW5kdGVs?= wrote on 18 feb 2004 in
microsoft.public.inetserver.asp.general:
If I have a value that is 53.123499999, how can I round it to 53.12?

The old and safe way:

n = 53.123499999

n = int( n * 100 + 0.5 ) / 100

n = int(n) / 100

Response.Write FormatNumber(n,2)
 
M

Mark Schupp

In school, I was taught that you rounded 1 - 4 down, and 5 - 9 up (the way
the FormatNumber does rounding). I don't ever remember being taught
banker's rounding. You learn something new every day. :)

I used to get horribly upset when my children would come home and tell me
that they were being taught to round that way (arithmetic rounding). I was
taught the other way (banker's rounding). It wasn't until I researched the
issue (to prove I was right, of course) that I found out that there were 2
different ways. I guess it is logical to teach arithmetic rounding in a math
class but there should at least be a mention of the other method.

The trick is to be consistent. Another programmer and I once spent 3 days
tracking down a 6 cent out of balance condition in a hospitals books (tried
to give the accounting trolls the 6 cents but they wouldn't take it). The
cause: in one place arithmetic rounding was used while banker's rounding was
used elsewhere.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top