Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ToString("n0") causes problem

Discussion in 'Scripting' started by ozgurdugmeci, Oct 1, 2015.

  1. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    I have got 7 inputfields and there is a text which shows the total of these 7 inputfields.
    The script works just fine.
    When I tried to use ToString("n0") the adding function gave an error.

    var arrayo : int;
    var ipf : UnityEngine.UI.InputField;
    // This is how i get the value of inputfields.
    arrayo = parseInt(ipf.text);
    ....
    ....
    ipf.text = ""+ arrayo.ToString("n0");

    however the adding function is giving the error below.
    (FormatException: Input string was not in the correct format)

    can you help me?
    Code (JavaScript):
    1. for (i=0;i<sayx;i++)
    2.                 {
    3.                     ipf2= gtf[i].GetComponent(UnityEngine.UI.InputField);
    4.                     if (ipf2.text=="" )
    5.                     {
    6.                         //ipf2.text=""+0;
    7.                      
    8.                     }
    9.                     // here I add each inputfield values. this is where the error occures.
    10.                     dummyToplam=parseInt(ipf2.text);
    11.                     toplam = toplam+dummyToplam;
    12.                     //Debug.Log ("      " +toplam );
    13.                  
    14.                 }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Why are you feeding it "n0"? What format is that supposed to be? For ints, there's rarely any reason not to use the plain ToString() function.
     
  3. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    I want the numbers entered in inputfield to be seen 1.000 instead of 1000
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Have you tried with a capital N?
     
  5. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    now i tried.
    it is giving the same parsing problem.
     
  6. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    yes i have found the solution.
    it is the parsin method. when i used double.parse, it is solved.