Input string was not in a correct format in double.Parse

前端 未结 5 1487
遥遥无期
遥遥无期 2020-12-07 02:50

I am new to C#. I\'m trying to make a calculator, but the following error occurred:

Input string was not in a correct format.

T

5条回答
  •  我在风中等你
    2020-12-07 03:46

    Your code seems hard to understand whats the use of button_13 and button_14;

    I will assume your trying to do this:

    bool ifNew = true;
    double num1 ,num2,result;
    private void Add_Click(object sender, EventArgs e))
    {
       if(ifNew)
       {
    
        num1 =  Convert.ToDouble(textBox1.Text);
        textbox1.Clear();
        ifNew = false;
        result += num1;
    
       }
       else
       {
        num2 = Convert.ToDouble(textBox1.Text);
        textbox1.Clear();
        result += num2;
        num1 = 0D;
        num2 = 0D;
        ifNew = true;
       } 
    
    
    }
    
    private void Equals_Click(object sender, EventArgs e)
    {
       textboxl.Text = string.Format("{0:N}",result);
    }
    

    Or you could use Double.Parse in my Convert.ToDouble It depends on your operation but I am visualizing how to do add operation you can change and edit this depends on your operation

提交回复
热议问题