• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by DonkeyMalonkey · Jul 14, 2016 at 08:53 AM · javascriptstringparse

Format Exception when trying to parseFloat(String)

Hello, I have a problem with my script. For some reason i get a Format Exception when i try to parseFloat() a String that i get from an InputField.

The Exception:

FormatException: Invalid format. System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Double.cs:209) System.Single.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Single.cs:183) UnityScript.Lang.UnityBuiltins.parseFloat (System.String value) ButtonScript.Calc () (at Assets/Scripts/ButtonScript.js:61) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:144) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:621) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:756) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

The Code:

"#pragma strict

import UnityEngine.UI;"

 //INPUT STRINGS
 var input1 : String;
 var input2 : String;
 var input3 : String;
 var input4 : String;
 
 //INPUT FIELDS
 var inputF1 : InputField; //input Field 1
 var inputF2 : InputField; //__""__ 2  
 var inputF3 : InputField; //...
 var inputF4 : InputField; //...
 var result : Text;
 
  private final var R : float = 6371000; //Earth's radius in metre
 
 //INPUT VARIABLES
 var d : float; //distance to travel
 var a1 : float; //latitude in dezimals
 var b1 : float; //longitude in dezimals
 var brng : float; //Angle you are going to
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 //
 //BUTTON FUNCTIONS
 //
 function ExitButton(){
     Application.Quit();
 }
 
 function InputF1(){
     input1 = inputF1.text;
 }
 
 function InputF2(){
     input2 = inputF2.text;
 }
 
 function InputF3(){
     input3 = inputF3.text;
 }
 
 function InputF4(){
     input4 = inputF4.text;
 }
 
 function Calc(){
     //aFloat = parseFloat(input1);  I TRIED ALL THIS BEVORE WIHT ALL
     //bFloat = parseFloat(input2);    SIMPLE TEST. IT WORKED BACK THEN.
     //flaeche = aFloat * bFloat;
     //result.text = ""+surface;
     d = parseFloat(input3);
     a1 = parseFloat(input1);
     b1 = parseFloat(input2);
     brng = parseFloat(input4);
     var a2 = Mathf.Asin( Mathf.Sin(a1)*Mathf.Cos(d/R) +
                         Mathf.Cos(a1)*Mathf.Sin(d/R)*Mathf.Cos(brng) );
     var b2 = b1 + Mathf.Atan2(Mathf.Sin(brng)*Mathf.Sin(d/R)*Mathf.Cos(a1),
                              Mathf.Cos(d/R)-Mathf.Sin(a1)*Mathf.Sin(a2));
     result.text = a2+"°N "+b2+"°W "; 
 }
 //
 //BUTTON FUNCTIONS END
 //

I have no idea what this Exception is telling me. I am a more or less beginner programmer so please don´t be to harsh on me if the structure of the code is not that good.

The "result" variable is a Text variable which gets displayed in the UI.

Here a picture of the UI. (sry for it beeing German but i think that does not matter that much anyway.) alt text

Thanks in Advance! Lucas

coordinatecalc.png (52.0 kB)
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by DonkeyMalonkey · Jul 15, 2016 at 05:46 AM

Anyone? Could rly use a tip. Maybe i missed something? I have attached everything in the Inspector, so that´s not it.

EDIT WOW I am so stupid haha.. I copied the Input Fields so they all still had the first input field function. Thanks for the help anyways, I guess. Took me a few hours to find that stupid mistake but i did find it after all.

Maybe this post helps someone in the future.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by _Yash_ · Jul 14, 2016 at 10:59 AM

try float.Parse instead you can also use float.tryParse to handle invalid input

float converted = float.Parse("17463274");

Comment

People who like this

0 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DonkeyMalonkey · Jul 14, 2016 at 11:08 AM 0
Share

Ok, will try that right away. That´s c++ right? Does not matter anyway just curious :).

avatar image DonkeyMalonkey · Jul 14, 2016 at 11:12 AM 0
Share

Still got the same Exception with "float.Parse(someString);" As for float.tryParse, that does not work either. Or did you mean float.TryParse. But that does not work either.

Your answer

Hint: You can notify a user about this post by typing @username

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

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

85 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error FormatException: Input string was not in a correct format. 0 Answers

Parse string value to add to enum List 2 Answers

String Array = Anything? 1 Answer

Problem with Contains 0 Answers

\n Not picked up when reading string from file's name 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges