【发布时间】:2017-04-26 12:31:32
【问题描述】:
我正在创建一个小程序,但它会引发错误。
System.Format.Exception
在我添加最后一行之后很好:
- 如果用户没有输入任何价格,则会显示 MessageBox 错误。
private void button2_Click(object sender, EventArgs e)
{
float mont,ope,mont_ht;
mont = float.Parse(text_entrer.Text); // ERROR HERE : 'System.Format.Exception'
if (radioButton4.Checked)
{
text_resultat.Text = mont.ToString();
}
else if(radioButton5.Checked && radioButton1.Checked)
{
ope = mont * 20 / 100;
mont_ht = mont + ope;
text_resultat.Text = mont_ht.ToString();
}
else if (radioButton5.Checked && radioButton2.Checked)
{
ope = mont * 12 / 100;
mont_ht = mont + ope;
text_resultat.Text = mont_ht.ToString();
}
else if (radioButton5.Checked && radioButton3.Checked)
{
ope = mont * 5 / 100;
mont_ht = mont + ope;
text_resultat.Text = mont_ht.ToString();
}
if (String.IsNullOrEmpty(text_entrer.Text))
{
MessageBox.Show("no montant","EROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
这里是错误和调试值的截图:
【问题讨论】:
-
我什至无法正确阅读,我可以说这意味着您正在将某些东西转换为不是浮点数的浮点数。在尝试使用它之前检查输入
-
text_entrer.Text的值是多少? -
这是用户添加价格的第一个文本区域
-
该死的,当答案在帖子中时,我问了一个问题。代码块太长,我正在编辑你的问题,使它只包含有用的信息。所以其他人不要迷路。