Search code examples
htmlinternationalizationlocale

With a browser, how do I know which decimal separator the operating system uses?


I'm developing a Web application.

I need to display some decimal data correctly so that it can be copied and pasted into a certain GUI application that is not under my control.

The GUI application is locale-sensitive and it accepts only the correct decimal separator that is set in the system.

I can guess the decimal separator from Accept-Language and the guess will be correct in 95% cases, but sometimes it fails.

Is there any way to do it on server side (preferably, so that I can collect statistics), or on client side?

Update:

The whole point of the task is doing it automatically.

In fact, this Web application is a kind of online interface to a legacy GUI that helps to fill the forms correctly.

The kind of users that use it mostly have no idea on what a decimal separator is.

The Accept-Language solution is implemented and works, but I'd like to improve it.

Update2:

I need to retrive a very specific setting: decimal separator set in Control Panel / Regional and Language Options / Regional Options / Customize.

I deal with four kinds of operating systems:

  1. Russian Windows with a comma as a DS (80%).
  2. English Windows with a point as a DS (15%).
  3. Russian Windows with a point as a DS to make poorly written English applications work (4%).
  4. English Windows with a comma as a DS to make poorly written Russian applications work (1%).

All clients are in Russia and the legacy application deals with Russian goverment-issued forms, so asking for a country will yield 100% of Russian Federation, and GeoIP will yield 80% of Russian Federation and 20% of other (incorrect) answers.


Solution

  • Here is a simple JavaScript function that will return this information. Tested in Firefox, IE6, and IE7. I had to close and restart my browser in between every change to the setting under Control Panel / Regional and Language Options / Regional Options / Customize. However, it picked up not only the comma and period, but also oddball custom things, like the letter "a".

    function whatDecimalSeparator() {
        var n = 1.1;
        n = n.toLocaleString().substring(1, 2);
        return n;
    }
    

    function whatDecimalSeparator() {
        var n = 1.1;
        n = n.toLocaleString().substring(1, 2);
        return n;
    }
    
    console.log('You use "' + whatDecimalSeparator() + '" as Decimal seprator');

    Does this help?