To start with, don't use double.Parse to convert user input - if they make a single tiny mistake your app will crash. Use the
Double.TryParse Method (String, Double) (System)[
^] instead:
double a;
if (!double.TryParse(textBox1.Text, out a))
{
... report problem to user ...
return;
}
double b;
if (!double.TryParse(textBox2.Text, out b))
{
... report problem to user ...
return;
}
Remember, users make typing mistakes all the time, just as we do! :laugh:
Then you can use either the
Math.Round Method (Double) (System)[
^] or
Math.Round Method (Double, Int32) (System)[
^] to round the result of your calculation.
label1.Text = Math.Round(a / b).ToString();
BTW: Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...