Converting textbox string to float?

后端 未结 2 615
臣服心动
臣服心动 2021-01-22 12:28

I\'m basically trying to write a basic converter in visual studio 2008, and I have 2 text boxes, one which gets input from the user, and one which gives output with the result.

2条回答
  •  天命终不由人
    2021-01-22 12:56

    You're trying to multiply a string by a double and there is no operator that defines how to do that. You need to convert your string to a double first, and then use that in the calculation.

    Then, you're trying to assign a string to a float, which again is nonsense.. You need to calculate the float, then convert it to a string when assigning it to the textbox text field.

    Something like:

    String^ i1 = textBox1->Text;
    float rez = (Convert::ToDouble(i1)*4.35);
    textBox2->Text = rez.ToString();
    

提交回复
热议问题