Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 which 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 webapp is a kind of online interface to a legacy GUI which 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 period as a DS (15%).
  3. Russian Windows with a period 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 100% of 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.

like image 975
Quassnoi Avatar asked Jul 02 '09 14:07

Quassnoi


People also ask

How to change decimal separator in access?

Click File > Options. On the Advanced tab, under Editing options, clear the Use system separators check box. Type new separators in the Decimal separator and Thousands separator boxes.

What is the correct decimal separator?

Great Britain and the United States are two of the few places in the world that use a period to indicate the decimal place. Many other countries use a comma instead. The decimal separator is also called the radix character.


1 Answers

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?

like image 157
Chris Nielsen Avatar answered Sep 19 '22 07:09

Chris Nielsen