1

Based on the following question,

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

I have tried to get the system decimal separator.

It doesn't work in google chrome.

https://bugs.chromium.org/p/chromium/issues/detail?id=120473

Is there any workaround or hack to get the decimal separator in Google Chrome?

Renganathan M G
  • 5,039
  • 2
  • 31
  • 35
  • My advice would be to allow them to select a language and or country. If you are looking for a hack I doubt one exists. You might be able to infer something with ip address & keyboard layout(not easily detected) & [browser language](https://github.com/dansingerman/jQuery-Browser-Language). – Lime Aug 01 '17 at 23:29

1 Answers1

2

I do not believe this is possible, browsers depend on the currently selected language in the browser to format numbers and dates so the following code in chrome with English as language will always return dot .

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

Now changing the previous code to use the German language for example

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

Will always return comma ,

So basically this is system independent solution

Hyyan Abo Fakher
  • 3,497
  • 3
  • 21
  • 35