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

Whole numbers

P: n/a
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
Share this Question
Share on Google+
17 Replies


P: n/a

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

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

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

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

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

P: n/a
* =?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

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

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

P: n/a
* =?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

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

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

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

P: n/a

"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

P: n/a
:)

--

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

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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.