473,382 Members | 1,305 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,382 software developers and data experts.

Whole numbers

I've forgotten.

How do I round off numbers from an equation or round off to the third
decimal point for instance.

eg.
answers number is 12345.678910

I would like to see answer as 12345.67 or .68

Thanks

Nov 21 '05 #1
17 1669

How do I round off numbers from an equation or round off to the third
decimal point for instance.


A simple method for rounding is to add 1/2 of the decimal place you wish
to round to, then perform an int function to remove the decimal point:

a=.4
a+=.5
a=int(a) 'a is now 0
a=1.26
a+=.05
a=int(a) ' a is now1.3
Nov 21 '05 #2
Me.TextBox1.Text = Math.Round(5.123456, 3)
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
I've forgotten.

How do I round off numbers from an equation or round off to the third
decimal point for instance.

eg.
answers number is 12345.678910

I would like to see answer as 12345.67 or .68

Thanks

Nov 21 '05 #3
=?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> wrote in
news:51**********************************@microsof t.com:
I've forgotten.

How do I round off numbers from an equation or round off to the third
decimal point for instance.

eg.
answers number is 12345.678910

I would like to see answer as 12345.67 or .68

Look at the functions:

System.Math.Round
FormatNumber
System.Math.Floor
System.Math.Ceiling
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #4
us**@domain.invalid wrote in news:OK**************@TK2MSFTNGP10.phx.gbl:

How do I round off numbers from an equation or round off to the third
decimal point for instance.


A simple method for rounding is to add 1/2 of the decimal place you wish
to round to, then perform an int function to remove the decimal point:

Why not use System.Math.round or one of the many other rounding functions?

seems easier : )

Nov 21 '05 #5
To round the number itself, use the Math.Round static method.

For example, Math.Round(123.45678, 3) produces 123.457.

To leave the number with its full precision, but print a rounded number, use
String.Format().

For example, String.Format("{0:0.000}", 123.45678) produces the string
"123.457"

One caution: the Math.Round() function uses "banker's rounding" which,
rounds to even digits if the number is halfway between; for example,
123.4565 and 123.4555 both round to 123.456.

However, the String.Format() function appears to round up, so that 123.4565
rounds to "123.457".

HTH,
Tom Dacon
Dacon Software Consulting

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
I've forgotten.

How do I round off numbers from an equation or round off to the third
decimal point for instance.

eg.
answers number is 12345.678910

I would like to see answer as 12345.67 or .68

Thanks

Nov 21 '05 #6
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
How do I round off numbers from an equation or round off to the third
decimal point for instance.


'Math.Round':

<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemMathClassRoundTopic.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2p************@uni-berlin.de...
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
How do I round off numbers from an equation or round off to the third
decimal point for instance.
'Math.Round':

<URL:http://msdn.microsoft.com/library/en...ystemMathClass
RoundTopic.asp>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


But how about Banker's rounding? I suspect that's included somewhere but I
haven't found it yet.
BobJ
Nov 21 '05 #8
Thanks for the help.

But I'd like to round to the second or third decimal point.

How do I do that?

"Herfried K. Wagner [MVP]" wrote:
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
How do I round off numbers from an equation or round off to the third
decimal point for instance.


'Math.Round':

<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemMathClassRoundTopic.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
But I'd like to round to the second or third decimal point.


\\\
Dim d As Double = Math.Round(12.3456, 3)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #10
<us**@domain.invalid> wrote in message
news:OK**************@TK2MSFTNGP10.phx.gbl...

How do I round off numbers from an equation or round off to the third
decimal point for instance.


A simple method for rounding is to add 1/2 of the decimal place you wish
to round to, then perform an int function to remove the decimal point:

a=.4
a+=.5
a=int(a) 'a is now 0
a=1.26
a+=.05
a=int(a) ' a is now1.3


Int will drop every thing to the right of the decimal place. So in this last
case a=1, not 1.3. The only way for this particular code to work is to shift
the number before and after the Int, as in:

a = 1.26
a += 0.05

a= Int(a * 10) / 10
Nov 21 '05 #11
Are you blind ?, I already answered this ! See above

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
Thanks for the help.

But I'd like to round to the second or third decimal point.

How do I do that?

"Herfried K. Wagner [MVP]" wrote:
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
How do I round off numbers from an equation or round off to the third
decimal point for instance.


'Math.Round':

<URL:http://msdn.microsoft.com/library/en...ystemMathClass
RoundTopic.asp>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #12
Hi Terry,

However I was glad with the anser from Tom, that banking rouding is awful in
my idea, is it maybe used in England?

Cor
Nov 21 '05 #13

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP11.phx.gbl...
Are you blind ?, I already answered this ! See above
I must be at least partially blind because I completely missed the
reference to banker's rounding the first time that I read your response.
Thank you for directing my attention to it so politely :)
BobJ
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
Thanks for the help.

But I'd like to round to the second or third decimal point.

How do I do that?

"Herfried K. Wagner [MVP]" wrote:
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
> How do I round off numbers from an equation or round off to the third > decimal point for instance.

'Math.Round':

<URL:http://msdn.microsoft.com/library/en...ystemMathClass RoundTopic.asp>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #14
:)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"BobJ" <bo*@rjsolyn.com> wrote in message
news:HU****************@newsread3.news.atl.earthli nk.net...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:ez**************@TK2MSFTNGP11.phx.gbl...
Are you blind ?, I already answered this ! See above


I must be at least partially blind because I completely missed the
reference to banker's rounding the first time that I read your response.
Thank you for directing my attention to it so politely :)
BobJ

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
Thanks for the help.

But I'd like to round to the second or third decimal point.

How do I do that?

"Herfried K. Wagner [MVP]" wrote:

> * =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
> > How do I round off numbers from an equation or round off to the third > > decimal point for instance.
>
> 'Math.Round':
>
>

<URL:http://msdn.microsoft.com/library/en...ystemMathClass
RoundTopic.asp>
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>



Nov 21 '05 #15
You'll get used to me, Im not that bad really !

;-)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"BobJ" <bo*@rjsolyn.com> wrote in message
news:HU****************@newsread3.news.atl.earthli nk.net...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:ez**************@TK2MSFTNGP11.phx.gbl...
Are you blind ?, I already answered this ! See above


I must be at least partially blind because I completely missed the
reference to banker's rounding the first time that I read your response.
Thank you for directing my attention to it so politely :)
BobJ

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
Thanks for the help.

But I'd like to round to the second or third decimal point.

How do I do that?

"Herfried K. Wagner [MVP]" wrote:

> * =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
> > How do I round off numbers from an equation or round off to the third > > decimal point for instance.
>
> 'Math.Round':
>
>

<URL:http://msdn.microsoft.com/library/en...ystemMathClass
RoundTopic.asp>
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>



Nov 21 '05 #16

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:Os*************@TK2MSFTNGP09.phx.gbl...
You'll get used to me, Im not that bad really !

;-)
At least no worse than I am! No need to choose weapons. Except perhaps a
weapon to bury that weird banker's rounding. :)
BobJ
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"BobJ" <bo*@rjsolyn.com> wrote in message
news:HU****************@newsread3.news.atl.earthli nk.net...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in

message
news:ez**************@TK2MSFTNGP11.phx.gbl...
Are you blind ?, I already answered this ! See above


I must be at least partially blind because I completely missed the
reference to banker's rounding the first time that I read your response.
Thank you for directing my attention to it so politely :)
BobJ

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
> Thanks for the help.
>
> But I'd like to round to the second or third decimal point.
>
> How do I do that?
>
>
>
>
>
> "Herfried K. Wagner [MVP]" wrote:
>
> > * =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit: > > > How do I round off numbers from an equation or round off to the

third
> > > decimal point for instance.
> >
> > 'Math.Round':
> >
> >

<URL:http://msdn.microsoft.com/library/en...ystemMathClass
RoundTopic.asp>
> >
> > --
> > M S Herfried K. Wagner
> > M V P <URL:http://dotnet.mvps.org/>
> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
> >



Nov 21 '05 #17
Bob,
It appears that VS.NET 2005 (aka Whidbey, due out in 2005 sometime) will
have an option on Math.Round to use Banker's rounding or not.

http://lab.msdn.microsoft.com/librar...ntRounding.asp

http://lab.msdn.microsoft.com/librar...2_377913f1.asp

http://lab.msdn.microsoft.com/librar...3_377913f1.asp

Hope this helps
Jay
"BobJ" <bo*@rjsolyn.com> wrote in message
news:xv*****************@newsread3.news.atl.earthl ink.net...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:Os*************@TK2MSFTNGP09.phx.gbl...
You'll get used to me, Im not that bad really !

;-)

At least no worse than I am! No need to choose weapons. Except perhaps a
weapon to bury that weird banker's rounding. :)
BobJ
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"BobJ" <bo*@rjsolyn.com> wrote in message
news:HU****************@newsread3.news.atl.earthli nk.net...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in

message
news:ez**************@TK2MSFTNGP11.phx.gbl...
> Are you blind ?, I already answered this ! See above

I must be at least partially blind because I completely missed the
reference to banker's rounding the first time that I read your response. Thank you for directing my attention to it so politely :)
BobJ
>
> --
>
> OHM ( Terry Burns )
> . . . One-Handed-Man . . .
> If U Need My Email ,Ask Me
>
> Time flies when you don't know what you're doing
>
> "Dooglo" <Do****@discussions.microsoft.com> wrote in message
> news:22**********************************@microsof t.com...
> > Thanks for the help.
> >
> > But I'd like to round to the second or third decimal point.
> >
> > How do I do that?
> >
> >
> >
> >
> >
> > "Herfried K. Wagner [MVP]" wrote:
> >
> > > * =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit: > > > > How do I round off numbers from an equation or round off to the third
> > > > decimal point for instance.
> > >
> > > 'Math.Round':
> > >
> > >
>

<URL:http://msdn.microsoft.com/library/en...ystemMathClass
> RoundTopic.asp>
> > >
> > > --
> > > M S Herfried K. Wagner
> > > M V P <URL:http://dotnet.mvps.org/>
> > > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
> > >
>
>



Nov 21 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jack Higgs | last post by:
I'm building a maths program for year 6 children. Problem with division - I generate a random number between say 1 and 1000. I want to generate another random number which when divided by the...
8
by: Aspersion | last post by:
I'm building an ASP page that has a lot of text and graphics. There is a calculation facility on the page. The user enters several numbers in a form and presses a button to see the calculated...
4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
1
by: News | last post by:
I cannot figure out how to have a field in a simple table retain decimal parts of a whole number (integer). These values are immediately rounded up or down to the nearest integer. Any help is...
3
by: Neils Christoffersen | last post by:
Hey all, I wrote on Friday asking for some help moving a common subclass field up to the base class (original post and followup included below). This entails storing whole numbers inside float...
4
by: Will | last post by:
Hey guys Quick question: how do i find out if the remainder of 4 divided by 2 is a whole number ? NEED CODE PLEAS THANX IN ADVANCE
9
by: Alberto | last post by:
Eh unfortunately Google groups does not provide any longer a way to reply to the group for older posts (though the one I am referring to is not older than one month), and I happen to come back to...
5
by: John | last post by:
Which variable type (c#) can whole the largest whole number? I know this sounds silly but as double and decimal are made for numbers with decimals I am not sure. Also if anybody knows of any...
5
by: Randeh | last post by:
Simple bubbling sort algorithm, nothing fancy, just trying to find a way to validate each number value as it's entered without creating several arrays and loops using isdigit(). I need to validate...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.