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.

Did you try a comma , as a decimal instead of a point?
You must always think it can have something to do with your international settings in these kind of problems.

Comments
good catch..i wouldnt have thought of it either :p

That is just incredible. No I had not, and it was driving me nuts. Thank you.

I should be able to track down the specific setting, again Thank you so much.

This question has already been answered. Start a new discussion instead.