I'm trying to Convert the string "5.7" (from a textbox) in to a float like this:
float m = float.Parse(TextBox9.Text);
But I'm getting the following error:
System.FormatException: Input string was not in a correct format.
what is wrong please?
I'm trying to Convert the string "5.7" (from a textbox) in to a float like this:
float m = float.Parse(TextBox9.Text);
But I'm getting the following error:
System.FormatException: Input string was not in a correct format.
what is wrong please?
float.Parse(Textbox9.Text, CultureInfo.InvariantCulture.NumberFormat);
You et the exception, because the text in the TextBox9 does not fit the "country-rules" for a correct decimal number. Usually this happens, if the dot represents a thousand seperator and not the decimal point. Maybe you can use:
float number = float.Parse(TextBox9.Text, CultureInfo.InvariantCulture);
or
float number = float.Parse(TextBox9.Text, Thread.CurrentThread.CurrentUICulture);
To avoid the exception you can use:
float number;
if (!float.TryParse(TextBox9.Text,  out number))
    MessageBox.Show("Input must be a decimal number.");