473,699 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

round up

If I have a value that is 53.123499999, how can I round it to 53.12?
Jul 19 '05 #1
9 4758
"joeandtel" <an*******@disc ussions.microso ft.com> wrote in message
news:5E******** *************** ***********@mic rosoft.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******@NOyah oo.SPAMcom> wrote in message
news:Oz******** ******@tk2msftn gp13.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******@NOyah oo.SPAMcom> wrote in message
news:Oz******** ******@tk2msftn gp13.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******@NOyah oo.SPAMcom> wrote in message
news:ui******** ********@TK2MSF TNGP10.phx.gbl. ..
Peter Foti wrote:
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:Oz******** ******@tk2msftn gp13.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?am9lYW5kdGV s?= wrote on 18 feb 2004 in
microsoft.publi c.inetserver.as p.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******@NOyah oo.SPAMcom> wrote in message
news:ep******** ******@TK2MSFTN GP12.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***@Idontwan tnostinkingemai lfromyou.com> wrote in message
news:10******** *****@corp.supe rnews.com... "Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:ep******** ******@TK2MSFTN GP12.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
3120
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 value should be 3.71 I could round to the 3rd decimal place ROUND(X,3) and that would round it correctly to 3.71 but that would mean I would have to change the ROUND function in another
6
18666
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 and will convert between date/time and double automatically. The double value Access (or VB) creates is based on 1 day = 1.0 and the fractional part represents a
17
5643
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 x=3.24 , result is is false
9
7379
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 different. Programming Microsoft Windows with Microsoft Visual Basic.NET "The Round method with a single argument return the whole number nearest to the argument. If the argument to Round is midway between two whole numbers,
4
7248
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 the value to one decimal place with a zero EG:
10
16020
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) 0.74
7
4468
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 -".number_format(20.545, 2, ',', '.')."<br>"; echo "number_format 20.555 -".number_format(20.555, 2, ',', '.')."<br>"; PHP Version 4.3.0 / FreeBSD
3
1827
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 expecting 12.2
4
10886
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
6553
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 function round() as seen below: 0 2 2
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.