I need a way to automatically format Date and Number objects based on locale settings of my users.
So far, I've been using toLocaleString()
function for dates. For numbers, toLocaleString()
is also available, but as you can see in the jsFiddle I've prepared, results vary greatly between browsers. With English (United States) locale on my Windows machine, I get this:
- IE9: 15,000.00
- Firefox: 15,000
- Chrome: 15000
In Chrome, it seems like toLocaleString()
does not work at all for numbers. Except this approach, I've also tried:
- To use MicrosoftAjax.js library
localeFormat()
function, but no matter which locale I've set on my PC (by using "Region and Language" dialog), dates and numbers were still both formated in US format. - To use libraries like Globalize. Although they do offer formatting capabilities, they are not able to detect user's locale automatically.
So, to summarize: how to automatically format numbers and dates to respect regional settings of user that browses the webpage in a way that works in all major browsers (IE, Firefox, Chrome)?