Hello,
I am having some trouble debugging a simple windows forms application. I have four textboxes, two being readonly that display the calculated answers, and then a "calculate" button.
here is the code for the calculate button:
private void btnCalculate_Click(object sender, EventArgs e)
{
decimal obj_height = Convert.ToDecimal(txtHeight.Text);
decimal obj_width = Convert.ToDecimal(txtWidth.Text);
decimal obj_area = obj_height * obj_width;
decimal obj_perimeter = 2 * obj_height + 2 * obj_width;
txtArea.Text = obj_area.ToString("n");
txtPerimeter.Text = obj_perimeter.ToString("n");
}
Everything works fine as long as i input integer values, that have no decimal. As soon as I enter anything with a decimal, I get a format exception.
In other words:
If I input 10, and 5: I get correct answers.
If I input 10.0 and 5: exception.
If I input 10.5 and 5: exception.
I have tried breaking my statements up some, using double instead of decimal or saving the .Text as a string and then trying to convert the variable, but I always get the same error. I have tried searching on this forum and google but I have not found an answer.
I am new to c# and I am worried that I am just missing some simple logic or scope issue?
I am using visual studio 2008 if that would be relevant. Did I forget any other info that would be useful?
Thank you for taking the time to read this.