Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

float.parse(string s) crash

Discussion in 'Samsung Smart TV' started by awen zhang, Jul 24, 2015.

  1. awen zhang

    awen zhang

    Joined:
    May 13, 2015
    Posts:
    1
    when I set the language of TV to the French, the below method would be crashed.

    float.Parse(string s)


    FormatException: Unknown char: .
    at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in <filename unknown>:0
    at System.Single.Parse (System.String s) [0x00000] in <filename unknown>:0
    at XmlHelper.GetFloatAttribute (System.Xml.XmlNode node, System.String attributeName) [0x00000] in <filename unknown>:0
    at PlayerWeaponDataImpl.Init (System.Xml.XmlNode node) [0x00000] in <filename unknown>:0
    at WeaponManager.LoadPlayerWeaponsFromConfig (System.Xml.XmlNode weaponsRoot) [0x00000] in <filename unknown>:0
    at WeaponManager.LoadConfig () [0x00000] in <filename unknown>:0
    at WeaponManager.Init () [0x00000] in <filename unknown>:0
    at WeaponManager..ctor () [0x00000] in <filename unknown>:0
    at Singleton.Init () [0x00000] in <filename unknown>:0
    at Singleton.get_Instance () [0x00000] in <filename unknown>:0
    at Boot+<StartGameplay>c__Iterator25.MoveNext () [0x00000] in <filename unknown>:0
     
  2. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Which version of Unity you use to build?
     
  3. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    What does your code look like?
     
  4. Jaehyun

    Jaehyun

    Unity Technologies

    Joined:
    Feb 4, 2014
    Posts:
    55
    Hi,
    I think French has special meaning about '.'.
    So please use float.Parse(string s, NumberStyles style, IFormatProvider provider) instead of float.Parse(string s) like below one.
    float f = float.Parse("0.2", System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture);​
     
  5. rahull1616dass

    rahull1616dass

    Joined:
    Oct 3, 2017
    Posts:
    24
    It'll be
    float f = float.Parse("0.2", System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);