Search Unity

update to unity 2019 and float.TryParse going to delete my decimal point

Discussion in 'Scripting' started by MrGky93, Apr 26, 2019.

  1. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    Can somone help me when i use

    Code (CSharp):
    1.   string[] values = {"160.519" };
    2.     // Start is called before the first frame update
    3.     void Start()
    4.     {
    5.    
    6.       foreach (var value in values)
    7.       {
    8.          float number;
    9.  
    10.          float.TryParse(value, out number);
    11.           Debug.Log(""+number);
    12.            
    13.     }
    I get

    Code (CSharp):
    1. 160519
    2. UnityEngine.Debug:Log(Object)
    Why i get this?
    In unity3d 2018 its works perfect!
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Works just fine for me. What else are you doing in that script?
     
  3. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    i have in unity 2018 scripting runtime net 3.x and in unity 2019 net 4.x.

    Edit : change to 4.x and you become the same bug debug give you 160519
    And when you use 3.x you become in the debug.log 160.519 very confused
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  5. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    thx for that here is the fix from @gresolio https://forum.unity.com/threads/editor-is-using-windows-locale-settings.442847/#post-3958150

    just create a c#file with the name FixCultureEditor and copy past the code from @gresolio
    Code (CSharp):
    1. using System.Globalization;
    2. using System.Threading;
    3. using UnityEngine;
    4. #if UNITY_EDITOR
    5. using UnityEditor;
    6. #endif
    7. #if UNITY_EDITOR
    8. [InitializeOnLoad]
    9. public static class FixCultureEditor
    10. {
    11.     static FixCultureEditor()
    12.     {
    13.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    14.     }
    15. }
    16. #endif
    17. public static class FixCultureRuntime
    18. {
    19.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    20.     static void FixCulture()
    21.     {
    22.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    23.     }
    24. }
    Hope unity fix this with the decimal point bug