Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert textbox to float

Tags:

c#

double

textbox

I've been looking for different ways to do it, but I still get the same error:

What I've tried:

float e = (float)Convert.ToDouble(e_textBox.Text);
bool valid = float.TryParse(e_textBox.Text.ToString(), out e);

And I get this error:

Error   1   Cannot implicitly convert type 'float' to 'System.EventArgs'

am I doing that wrong? Thank you.

like image 872
b-fg Avatar asked Jun 16 '26 10:06

b-fg


1 Answers

I'm guessing your code lives inside an event handler. One of the parameters to your handle will be EventArgs e:

public void OnClick(object sender, EventArgs e)
{
    float e = (float)Convert.ToDouble(e_textBox.Text);
    bool valid = float.TryParse(e_textBox.Text.ToString(), out e);
}

You just need to come up with a new variable name (or rename the parameter to something other than e):

public void OnClick(object sender, EventArgs eargs)
{
    float e = (float)Convert.ToDouble(e_textBox.Text);
    bool valid = float.TryParse(e_textBox.Text.ToString(), out e);
}
like image 105
Justin Niessner Avatar answered Jun 17 '26 22:06

Justin Niessner