- Home /
Float.Parse question
I'm trying to convert a string, entered by the player into a Gui.textfield, into a float. However, Im constantly getting this error: "FormatException: Invalid format. System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) System.Single.Parse (System.String s)"
My code is as follows:
string str_inputAmount = "";
str_inputAmount = GUI.TextField(new Rect(v3_screenPos.x + 55f, v3_screenPos.y - (i * 55f), 50f, 50f), str_inputAmount, 4);
float inputAmount = 0f;
inputAmount = float.Parse(str_inputAmount);
What could my solution be?
Answer by robertmathew · Apr 04, 2011 at 02:57 PM
http://answers.unity3d.com/questions/47763/convert-string-to-float-or-double-errors
string myString = "15.5"; float number = (float) int.Parse(myString);
float num = System.Convert.ToSingle( myString );//or this
Now Im getting the error "Input string is not in the correct format"...
Your answer
Follow this Question
Related Questions
invalid format exception when parsing float 2 Answers
xml : FormatException: Input string was not in the correct format 1 Answer
Parse Exception System.AggregateException 0 Answers
convert object to float 2 Answers
Converting Variables 3 Answers