Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Decimal separator randomly becoming something that looks like a comma

Discussion in 'Editor & General Support' started by ReiMari, Jul 18, 2014.

  1. ReiMari

    ReiMari

    Joined:
    May 15, 2013
    Posts:
    5
    All values in the inspector have started showing the decimal separator as something that looks like a comma but upon closer inspection is something completely different; while it should be a dot.
    The character I'm referring to is: ٫ Compared to a comma: ,

    This all started after I've opened a project someone else made.
    At first only a few values would use a not-exactly-a-comma, and all other values would use a dot as the decimal separator.
    As more time passed more and more values started using a not-exactly-a-comma, until eventually all values use it.
    This happens in all projects, even after re-installing Unity and trying a few different versions.
    Now I've sent a project, completely different from the one that initally caused all of this to happen, to someone else and now the same thing is happening in his installation of Unity.

    This causes problems in copy-pasting values into the inspector (they get set to 0), and in parsing floats in script.
    Setting the main thread's culture to CultureInfo.InvariantCulture from an editor script fixes it for about 3 actions in the editor before it all goes wrong again.
     
  2. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    Check that your mono instance is not set to a different country code. It is possible that the decimal separator . isn't what is used in that country.
     
  3. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
  4. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Was poking about, and came up with this, which I guess you already know:

    Code (csharp):
    1.  
    2. #pragma strict
    3. //js code
    4. import System.Globalization;
    5.  
    6. function Start () {
    7.  
    8.     var ci : CultureInfo = CultureInfo("ar-SA");
    9.     var nfi : NumberFormatInfo  = ci.NumberFormat;
    10.    
    11.     Debug.Log("<" + nfi.NumberDecimalSeparator + ">");
    12. }
    Guess this just shows us that the Arabic decimal digit is the "not a comma". Are you on a PC? What does control panel tell you the decimal digit is? When Unity reverts to the "not a comma" does Windows revert to it? I guess I mean, is Unity picking this "not a comma" from the system.
     
  5. ReiMari

    ReiMari

    Joined:
    May 15, 2013
    Posts:
    5
    Thanks for the quick replies.

    I'm not using Mono (nor have I ever used it), I'm using Visual Studio which as far as I know doesn't have any issues.
    The system is set to Dutch, where a normal comma is used instead of the Arabic one. It's also only happening in Unity. The only installed language pack is Dutch so it can't switch randomly either.
    The normal comma: "," is used as the decimal separator in this pack (which I've checked in the control panel).

    Edit:
    It looks like changing the decimal separator in the control panel to a dot has fixed it. But since it started slowly and randomly it's hard to tell if that really fixed it without giving it some time, so for now: thanks!
     
  6. ReiMari

    ReiMari

    Joined:
    May 15, 2013
    Posts:
    5
    The problem returned.
    I've done a quick check to see what just C# by itself does with decimal separators and everything seems fine when I run the following code in a console application:

    Code (CSharp):
    1. Console.WriteLine((2.4389f).ToString());
    2. Console.WriteLine(float.Parse("4.5389").ToString());
    3. Console.ReadKey();
    This returns:
    2.4389
    4.5389
    So I'm pretty sure now that the system is doing everything as it should. Which makes everything kind of weird as there's no real reason for this to happen at all.
     
  7. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    970
    You are and always have been. Mono != MonoDevelop. Mono is the runtime environment running the entire scripting side of Unity, including the editor.
     
  8. ReiMari

    ReiMari

    Joined:
    May 15, 2013
    Posts:
    5
    Right, must have forgotten about that since it all looks so similar (which is kind of the point). My apologies.
    Do you happen to know where the country setting for that might be?
    Searching on google yielded no results for me.
     
  9. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,623
    indeed, decimal separator is culture specific. To avoid going into control panel, etc you can try adding this somewhere on startup
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
    NB: it might not work on ios
     
  10. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
  11. ReiMari

    ReiMari

    Joined:
    May 15, 2013
    Posts:
    5
    Fixed it by having an editor script constantly checking the culture, and then set it back to en-US if it changed. I hope this permanently solves the problem.

    Thanks for all the help!
     
  12. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Really odd if it's happening periodically and needs resetting. I'm still not clear if this problem is the Mono runtime in Unity seeing the system settings have changed, or if the Mono runtime is changing. If system settings have changed (meaning Control Panel shows you with a "not a comma" as the decimal digit), then I'd be deeply concerned that something unknown is changing system settings.
     
  13. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Just bumping this to say something like this exact thing happens to me running a USA copy of Windows and everything in Windows reports decimal period and yet Unity randomly changes it in the editor to a comma. I created a .net app to report decimal separators to run when Unity starts changing all my float separators to commas and it still works correctly. Visual Studio is fine, Windows is fine, Unity is the only thing that wigs out on decimals.
     
    rjevans likes this.
  14. rjevans

    rjevans

    Joined:
    Sep 24, 2010
    Posts:
    24
    I'm hitting this as well. Unity 4.6.0f3, Windows 8.1. US copy of windows, never messed with any localization stuff. Checked my codebase to make sure nothing is manually setting the current culture. Very, very frustrating.

    If it helps track this down, it appears to be windows specific. I haven been unable to reproduce the issue on os x.
     
  15. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    I have this same problem, never had it before but now its happening a lot.
    Windows 8.1, 4.6.0f3
    I use this in my editor scripts: float.Parse(input,System.Globalization.CultureInfo.InvariantCulture);
    But I cannot see how that would change the culture settings in unity. No other programs are affected, just Unity.

    Any ideas?
     
  16. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    I can confirm this only happens in the unity editor. If I build the game and run it as standalone I do not get this behaviour. This is the character that the Unity editor is converting the decimal separator to: ٫
     
  17. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    I did a check and when this error happens, Thread.CurrentThread.CurrentCulture.DisplayName is null. If I then set it to english the problem goes away. So something is making the CurrentCulture null and it seems to default to arabic for the decimal separater which makes sense if Arabic is the first language in the list of options.

    --I've also submitted a bug report in case that helps:
    Case 661755
     
    Last edited: Jan 8, 2015
    Graham-Dunnett likes this.
  18. LethalInjection

    LethalInjection

    Joined:
    Jan 25, 2015
    Posts:
    37
    I was also getting commas and period's in number in UK format. 5.00.000,41241. It was my fault, I installed the UK version of Windows 8.1 from MSDN. I tried fixing by downloading the US English language pack. I was able to change windows by updating region/local in control panel, but unity never changed. When I sent output to a file, the wrong characters were displayed for commas. Script also returned blank for Thread.CurrentThread.CurrentCulture.DisplayName.
    This was fixed by going into 'language' in control panel, then into 'Advanced Settings', then override 'windows display language 'to 'English US' and 'override for default input method' to 'English (United States) - US'
    This maybe a year old thread, but google says its the most relevant. Happy Developing....
     
  19. Chris_Payne_QS

    Chris_Payne_QS

    Joined:
    Jul 16, 2016
    Posts:
    84
    I've just had this in 2018.2.5f1 - numeric seperator changed to Arabic although the Windows seperator and other language settings are all still English/UK.
    It was because the game manually set the invariant culture during a session (necessary to make JSON output consistent on Linux):

    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

    This works fine, but it seems the editor tries to revert CurrentCulture when the play session ends, and gets it wrong. Subsequent play sessions in scenes which did NOT set the culture manually then used the wrong culture. I've worked around it by ensuring the invariant culture is always set manually.
     
    prognosist likes this.
  20. gresolio

    gresolio

    Joined:
    Jan 5, 2014
    Posts:
    17
    Editor is using Window's locale settings
    Code (CSharp):
    1. using System.Globalization;
    2. using System.Threading;
    3. using UnityEngine;
    4. #if UNITY_EDITOR
    5. using UnityEditor;
    6. #endif
    7.  
    8. #if UNITY_EDITOR
    9. [InitializeOnLoad]
    10. public static class FixCultureEditor
    11. {
    12.     static FixCultureEditor()
    13.     {
    14.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    15.     }
    16. }
    17. #endif
    18.  
    19. public static class FixCultureRuntime
    20. {
    21.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    22.     static void FixCulture()
    23.     {
    24.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    25.     }
    26. }
     
    heu3becteh, Zottman, 600 and 2 others like this.
  21. Tom-Mensink

    Tom-Mensink

    Joined:
    Jul 27, 2017
    Posts:
    17
    Setting the Scripting Runtime Version to .Net 4.x Equivalent (Unity version 2018.2.13f1) now also messes up the locale. Numbers show for instance 1,1 instead of 1.1 in the editor, and also parsing text string runtime are using the wrong locale now. I filed a bug report for this

    Adding a script with the solution of @gresolio seems to be a great quick fix, thank you!
     
    Last edited: Dec 5, 2018
  22. bobdonovan

    bobdonovan

    Unity Technologies

    Joined:
    Aug 2, 2017
    Posts:
    14
    This is fixed in 2018.3. We now use decimal points everywhere with Scripting Runtime Version to .Net 4.x Equivalent.
     
    Tom-Mensink likes this.
  23. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    349
    This is not fixed for me. I still have commas in the editor everywhere.
     
  24. Bitfabrikken

    Bitfabrikken

    Joined:
    Mar 24, 2013
    Posts:
    34
    Not fixed for me either. Still have commas instead of periods in the Editor, plus all my JSON files with decimal values are getting completely screwed up.
     
    ratking likes this.
  25. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    349
    The worst thing is that the bug report in the Tracker say it's "fixed in 2019.1" :( I wish this was applied to 2018.3 too!
     
  26. theplake

    theplake

    Joined:
    Feb 12, 2015
    Posts:
    1
    I need dots! :) i write a ini file and all my floats are with ",". what is this ?

    Edit: okay its the os language. Is there a way that Unity doesnt use the os language?
     
    Last edited: Jan 6, 2019
  27. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    349
    @bobdonovan: Is this finally *really* fixed in 2018.3.2?
     
  28. gresolio

    gresolio

    Joined:
    Jan 5, 2014
    Posts:
    17
    ratking likes this.
  29. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Ive recently updated to 2018.3.9 and immediately had a couple of players report the most recent beta branch is unplayable. I found out one of the is using Danish as the primary language for his Windows 10. I switched mine to Danish and am now getting this. Not only does the editor use commas instead of periods to represent decimal places, the player camera which starts at x0.3996813 (for no real reason) is starting at 0,3996813 or 3996 kilometers south. My floating point error correction system kicks in and shifts the world 3996 kilometers breaking everything.

    I build and export the game from an English Windows 10. But playing the game on a Danish Windows 10 is now no longer possible. The current live branch is still 2018.2.2 and works fine.

    The script on page 1 from gresolio fixed it.
     
  30. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    349
    Does an update to 2018.3.11 or 2018.3.12 fix it?
     
  31. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    I'm developing a live game and honestly updating is the last thing I ever want to do. I was forced to update from 2018.2.2 because the cursor lock just didn't work at all in that version, and sure enough updating again I now how entirely different problems to deal with. Seeing as the forcing invariant method seems to have fixed it I'm sticking with 2018.3.9 until there is an absolute need to upgrade again. Though it may very well be fixed in 11 as mentioned above.

    now it seems that Unity 2018.3.9 is incapable of turning VSync off =[ There's always some stupid problem that's fixed in a later version that's got something else in it that's broken. Time to go make a post about that now
     
    Last edited: Apr 9, 2019
  32. DrEvil

    DrEvil

    Joined:
    Aug 11, 2012
    Posts:
    22
  33. hromoyDron

    hromoyDron

    Joined:
    Jan 24, 2013
    Posts:
    90
    I was on 2018.4 all was ok, but I updated to 2019.2 and now it want commas, not dots.
    Is it a bug?
     
  34. Sonic1305

    Sonic1305

    Joined:
    Jan 24, 2018
    Posts:
    1
    Issue still present
     
  35. Viikable

    Viikable

    Joined:
    Apr 12, 2018
    Posts:
    10
    Very interesting this indeed, I was struggling with this for a while, but setting the thread on Start() works and now everything runs as it should be. Really frustrating though as setting the variables in the Parse-method seem to do nothing and just throws errors or you get this comma (or a comma at least), and basically everywhere related to this except in this thread everyone just keeps saying to use Parse(string, InvariantCulture) which does not work at all.