I am doing some Rounding and calculations on a Web form. When I debug the program everything else works until I get to the Rounding part. I get and error "Input string was not in a correct format". So I comment out that section and debugged the program again. The Rounding works and displays. When it is trying to add the numbers it throws the Input string was not in a correct format error. What did I do wrong?
Here is all of the code:
protected void TextBoxTHUG_TextChanged(object sender, EventArgs e)
{
int i = Convert.ToInt32(TextBoxTHUG.Text.Replace(",", ""));
TextBoxTHUGDR.Text = Convert.ToString(i / 12.0);
int a = Convert.ToInt32(TextBoxFTUG.Text.Replace(",", ""));
int b = Convert.ToInt32(TextBoxFTG.Text.Replace(",", ""));
int c = Convert.ToInt32(TextBoxTHUGDR.Text.Replace(",", ""));
int d = Convert.ToInt32(TextBoxTHGDR.Text.Replace(",", ""));
TextBoxT1234.Text = Convert.ToString(a + b + c + d);
int g = Convert.ToInt32(TextBoxT1234.Text.Replace(",", ""));
int f = Convert.ToInt32(TextBoxNCCDR.Text.Replace(",", ""));
TextBoxTCNC.Text = Convert.ToString(g + f);
int o = Convert.ToInt32(TextBoxLYTCNC.Text.Replace(",", ""));
int p = Convert.ToInt32(TextBoxTCNC.Text.Replace(",", ""));
TextBoxFTE40.Text = Convert.ToString(Math.Round((Math.Abs(p - o) * 100.0 / ((o)))));
TextBoxFTE40.Text = Math.Round(Convert.ToDouble(TextBoxFTE40.Text), 2).ToString();
RangeValidatorLYTHUGDR.Validate();
RangeValidatorLYTCNC.Validate();
TextBoxTHUGDR.Text = Math.Round(Convert.ToDouble(TextBoxTHUGDR.Text.ToString()), 2).ToString();
TextBoxTHUGDR.Text = string.Format("{0:0,0}", double.Parse(TextBoxTHUGDR.Text));
TextBoxTHUG.Text = string.Format("{0:0,0}", double.Parse(TextBoxTHUG.Text));
TextBoxT1234.Text = string.Format("{0:0,0}", double.Parse(TextBoxT1234.Text));
TextBoxTCNC.Text = string.Format("{0:0,0}", double.Parse(TextBoxTCNC.Text));
TextBoxTHG.Focus();
}
Here is where the error is throwing:
int c = Convert.ToInt32(TextBoxTHUGDR.Text.Replace(",", ""));
How can I fix this?