x


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?

more ▼

asked Apr 04 '11 at 02:46 PM

Jordi 5 gravatar image

Jordi 5
1 2 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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
more ▼

answered Apr 04 '11 at 02:57 PM

robertmathew gravatar image

robertmathew
571 35 39 51

Now Im getting the error "Input string is not in the correct format"...

Apr 04 '11 at 03:00 PM Jordi 5
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x225
x182
x128
x34
x7

asked: Apr 04 '11 at 02:46 PM

Seen: 2652 times

Last Updated: Apr 04 '11 at 02:46 PM