Each browser supports Number.prototype.toLocaleString() , a method designed to return a localized string from a number. However, the specification defines it as follows:
Produces a string value that represents the value of a number formatted according to the conventions of the current locale of the host environment. This function is implementation dependent and valid, but is not encouraged to return the same as toString .
Dependence on implementation means that the supplier must understand what the result will look like and will lead to compatibility issues.
Internet Explorer (from IE 5.5 to IE 9) is closest to what you want and formats a currency-style number - the thousands separator and is fixed at 2 decimal places.
Firefox (2+) formats thousands and decimal places, but only if applicable.
Opera, Chrome, and Safari are displayed in the same way as toString() - without thousands separators, decimal if required.
Decision
I came up with the following code (based on my old answer ) to try to normalize the results to work as an Internet Explorer method:
(function (old) { var dec = 0.12 .toLocaleString().charAt(1), tho = dec === "." ? "," : "."; if (1000 .toLocaleString() !== "1,000.00") { Number.prototype.toLocaleString = function () { var neg = this < 0, f = this.toFixed(2).slice(+neg); return (neg ? "-" : "") + f.slice(0,-3).replace(/(?=(?!^)(?:\d{3})+(?!\d))/g, tho) + dec + f.slice(-2); } } })(Number.prototype.toLocaleString);
This will use the built-in localization of the browser, if available, while gracefully humiliating itself to the default browser language in other cases.
Working demo: http://jsfiddle.net/R4DKn/49/