Reputation: 36703
I was trying to convert a number say 123456.789
to India Locale Format wiz 1,23,456.789
as India uses thousands/lakh/crore separators.
I was successfully able to do this with some 10-20 lines of code and then I came to this article of MDN.
You see the line 11, they have declared a mechanism there to convert it
// India uses thousands/lakh/crore separators
console.log(number.toLocaleString('en-IN'));
// → 1,23,456.789
But it is not working (tested in Chrome v49.0.2623 and Safari)
Output in safari:
123456.789
Output in chrome:
123,456.789
But it worked in firefox
Output in Firefox:
1,23,456.789
But when I read the browser compatibility table it was stated that it is supported in chrome v24+
Is it a bug or am I doing something wrong?
var number = 123456.789
console.log(number.toLocaleString('en-IN'));
Upvotes: 10
Views: 11426
Reputation: 128791
This simply means that the en-IN
locale code isn't supported by Chrome (or Safari). You may have better luck using a different locale which uses the same format. An example of this is the Hindi locale code (hi
), which seems to return this format in Chrome, Firefox and Internet Explorer 11:
console.log((123456.789).toLocaleString('hi'));
-> 1,23,456.789
For what it's worth, MDN's support table only lists Basic Support. It determines which browsers implement the functionality, but it doesn't go as far as testing every possible use case.
Upvotes: 10