Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
2.40/5 (5 votes)
See more:
How to solve Error Operator '-' cannot be applied to operands of type 'float' and 'string'

What I have tried:

C#
private void textBox4_TextChanged(object sender, EventArgs e)
{
    try
    {
        textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text).ToString());
    }
    catch
    {

    }
}
Posted
Updated 5-Feb-17 10:15am
v2

Check the parentheses.
Your code:
C#
textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text).ToString());
Correct:
C#
textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text)).ToString();
 
Share this answer
 
Replace
C#
textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text).ToString());

with
C#
textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text)).ToString();

As usual with computer programs everyt
thing matters, missing space, position of () ...

Advice: use programmer editor like NotePad++, they show you how () are matching among other things.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900