本文介绍了输入字符串的格式不正确。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对Web表单进行一些舍入和计算。当我调试程序时,其他一切都有效,直到我进入Rounding部分。我得到错误输入字符串格式不正确。所以我注释掉那个部分并再次调试程序。舍入工作和显示。当它试图添加数字时,它会抛出输入字符串的格式错误。我做错了什么?



以下是所有代码:



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(",", ""));
            //int j = 12;
            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?

推荐答案


这篇关于输入字符串的格式不正确。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:48
查看更多