By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

round up

P: n/a
If I have a value that is 53.123499999, how can I round it to 53.12?
Jul 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"joeandtel" <an*******@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
If I have a value that is 53.123499999, how can I round it to 53.12?


FormatNumber( 53.123499999, 2 )

Regards,
Peter Foti
Jul 19 '05 #2

P: n/a
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.

Here's a link to the downloadable documentation:
http://www.microsoft.com/downloads/d...DisplayLang=en

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

P: n/a
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
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.

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

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?

The FormatNumber function will at least round in a sensible way (values of
5+ are rounded up, values of 4- are rounded down). For example:
FormatNumber( 22.5, 0 ) = 23
FormatNumber( 21.5, 0 ) = 22
Round( 22.5, 0 ) = 22
Round( 21.5, 0 ) = 22

Regards,
Peter Foti


Jul 19 '05 #4

P: n/a
Peter Foti wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
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.
Jul 19 '05 #5

P: n/a
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ui****************@TK2MSFTNGP10.phx.gbl...
Peter Foti wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
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


Doh! Sorry. :)

-Peter
Jul 19 '05 #6

P: n/a
=?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.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #7

P: n/a
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.
Jul 19 '05 #8

P: n/a
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ep**************@TK2MSFTNGP12.phx.gbl...
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
Jul 19 '05 #9

P: n/a
> 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
"Peter Foti" <pe***@Idontwantnostinkingemailfromyou.com> wrote in message
news:10*************@corp.supernews.com... "Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ep**************@TK2MSFTNGP12.phx.gbl...
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

Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.