Decimal separator randomly becoming something that looks like a comma

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.

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.

Guess that the “not a comma” is Unicode U+066B. See:

That character is used in Persian as a decimal point, so somehow you’re Unity thinks it’s Persian.

Was poking about, and came up with this, which I guess you already know:

#pragma strict
//js code
import System.Globalization;

function Start () {

    var ci : CultureInfo = CultureInfo("ar-SA");
    var nfi : NumberFormatInfo  = ci.NumberFormat;
   
    Debug.Log("<" + nfi.NumberDecimalSeparator + ">");
}

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.

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!

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:

Console.WriteLine((2.4389f).ToString());
Console.WriteLine(float.Parse("4.5389").ToString());
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.

You are and always have been. Mono != MonoDevelop. Mono is the runtime environment running the entire scripting side of Unity, including the editor.

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.

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

For iOS, take a look at the NSLocale class.

The following stackoverflow forum page may also be helpful.

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!

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.

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.

1 Like

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.

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?

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: ٫

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

1 Like

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…

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.

1 Like

Editor is using Window’s locale settings

using System.Globalization;
using System.Threading;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

#if UNITY_EDITOR
[InitializeOnLoad]
public static class FixCultureEditor
{
    static FixCultureEditor()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    }
}
#endif

public static class FixCultureRuntime
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void FixCulture()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    }
}
5 Likes