Velocity Reviews > round up

# round up

joeandtel
Guest
Posts: n/a

 02-18-2004
If I have a value that is 53.123499999, how can I round it to 53.12?

Bob Barrows [MVP]
Guest
Posts: n/a

 02-18-2004
joeandtel wrote:
> If I have a value that is 53.123499999, how can I round it to 53.12?

Umm - that's not rounding "up".

In vbscript, you can use the round() function.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Bob Barrows [MVP]
Guest
Posts: n/a

 02-18-2004
Peter Foti wrote:
> "Bob Barrows [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> joeandtel wrote:
>>> If I have a value that is 53.123499999, how can I round it to 53.12?

>>
>> Umm - that's not rounding "up".

>
>
> Bob, he didn't ask to round up... just to round it.
>

Look at the subject
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Bob Barrows [MVP]
Guest
Posts: n/a

 02-19-2004
Peter Foti wrote:
>
> 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
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Evertjan.
Guest
Posts: n/a

 02-19-2004
=?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)

--
Evertjan.
The Netherlands.

Mark Schupp
Guest
Posts: n/a

 02-19-2004
> 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
Integrity eLearning
www.ielearning.com

"Peter Foti" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Bob Barrows [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Peter Foti wrote:
> > >
> > > 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?

>
>
> I've never heard of this before. Though it seems to make sense.
>
>
> > 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.

>
>
> 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.
>
> -Pete
>
>