Whole numbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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
 
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 : )
 
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
 
Thanks for the help.

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

How do I do that?
 
* =?Utf-8?B?RG9vZ2xv?= said:
But I'd like to round to the second or third decimal point.

\\\
Dim d As Double = Math.Round(12.3456, 3)
///
 
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
 
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
 
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
 
One Handed Man ( OHM - Terry Burns ) said:
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
 
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
 
One Handed Man ( OHM - Terry Burns ) said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top