473,390 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

round up

If I have a value that is 53.123499999, how can I round it to 53.12?
Jul 19 '05 #1
9 4727
"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
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
"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
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
"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
=?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
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
"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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matias Silva | last post by:
Can anybody tell me why I am getting rounding errors using the ROUND function. 3.7125 rounds to 3.70 when I use the following: TRUNCATE(ROUND(units_pay_amount * fees_amount, 2),2))) The correct...
6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
17
by: nomenklatura | last post by:
Hi, System.Math.Round function is confused me. for example i want to round 3.245 in with decimal symbol Result should be = 3.25 When i try to this in vb: A = 3.245 X = Round(A, 2) then...
9
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something...
4
by: Fuzzydave | last post by:
I have been using a round command in a few places to round a value to zero decimal places using the following format, round('+value+', 0) but this consistantly returns the rounded result of...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
7
by: kkmigas | last post by:
Can some one explain if this can be fixed using php.ini settings ? echo "round 20.545 -".round(20.545,2)."<br>"; echo "round 20.555 -".round(20.555,2)."<br>"; echo "number_format 20.545...
3
by: Krishna.K.1900 | last post by:
Does round() always perfectly return the output expected or are there some artifacts which don't allow perfect functionality Using python 2.5: 12.23 12.234 12.199999999999999 but was...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
9
by: josh logan | last post by:
Hello, I need a round function that _always_ rounds to the higher integer if the argument is equidistant between two integers. In Python 3.0, this is not the advertised behavior of the built-in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.