T
Tony Johansson
I live in Sweden and we use decimalcomma for float, double and decimal
numbers but some
people might use decimalpoint so I just wonder what is the best solution to
support both in calculation.
The code below works fine for decimalcomma but get formatException saying
that input string had wrong format.
One solution is to replace decimalpoint with decimalcomma but I don't know
if that is the best solution
protected void Operation_Click(object sender, EventArgs e)
{
switch (((Button)sender).Text)
{
case "+" : txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) + Convert.ToDouble(txtNumber2.Text));
break;
case "-": txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) - Convert.ToDouble(txtNumber2.Text));
break;
case "*": txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) * Convert.ToDouble(txtNumber2.Text));
break;
case "/": txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) / Convert.ToDouble(txtNumber2.Text));
break;
}
}
//tony
numbers but some
people might use decimalpoint so I just wonder what is the best solution to
support both in calculation.
The code below works fine for decimalcomma but get formatException saying
that input string had wrong format.
One solution is to replace decimalpoint with decimalcomma but I don't know
if that is the best solution
protected void Operation_Click(object sender, EventArgs e)
{
switch (((Button)sender).Text)
{
case "+" : txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) + Convert.ToDouble(txtNumber2.Text));
break;
case "-": txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) - Convert.ToDouble(txtNumber2.Text));
break;
case "*": txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) * Convert.ToDouble(txtNumber2.Text));
break;
case "/": txtResult.Text = string.Format("{0:F3}",
Convert.ToDouble(txtNumber1.Text) / Convert.ToDouble(txtNumber2.Text));
break;
}
}
//tony