我收到错误“格式异常未处理”。和“输入字符串格式不正确”。它在这一行temp_i = float.Parse(textBox3.Text);问题是什么?格式异常未处理。输入字符串格式不正确
//button 2 calculate button
private void button1_Click(object sender, EventArgs e)
{
float temp_e;
float temp_i;
float temp_r;
float temp_p;
//*******************************************************
// Resistance = Volts/Current
//*******************************************************
if (IsNumeric(textBox1.Text) &&
IsNumeric(textBox2.Text) &&
textBox3.Text == (""))
{
temp_e = float.Parse(textBox1.Text); //convert string to number
temp_i = float.Parse(textBox3.Text); //convert string to number
temp_r = temp_e/temp_i; //display 1st result
textBox2.Text = Convert.ToString(temp_r); //post result resistance (R)
//calculate power
temp_p = temp_e * temp_i;
textBox5.Text = Convert.ToString(temp_p);
//display 2nd result
textBox4.Text = Convert.ToString(temp_r) + " * " + Convert.ToString(temp_i) + " = " + Convert.ToString(temp_p) + " watts";
}'
你会怎样想转换“”浮动?你确定 ?尝试删除该条件,否则解析并比较它。 – Milee 2012-04-23 11:02:17