There .toLocaleString() , but, unfortunately, the specification defines this as "implementation dependent" - I hate it when they do it. Thus, it behaves differently in different browsers:
var val = 1000000; alert(val.toLocaleString()) // -> IE: "1,000,000.00" // -> Firefox: "1,000,000" // -> Chrome, Opera, Safari: "1000000" (i know, it the same as toString()!)
Thus, you can see that you cannot rely on him because the ECMA team was too lazy to correctly define it. Internet Explorer does a better job of formatting it as a currency. You are better off with your own or someone else .
or
mine :
(function (old) { var dec = 0.12 .toLocaleString().charAt(1), tho = dec === "." ? "," : "."; if (1000 .toLocaleString() !== "1,000.00") { Number.prototype.toLocaleString = function () { var f = this.toFixed(2).slice(-2); return this.toFixed(2).slice(0,-3).replace(/(?=(?!^)(?:\d{3})+(?!\d))/g, tho) + dec + f; } } })(Number.prototype.toLocaleString);
Tested in IE, Firefox, Safari, Chrome and Opera only in my own locale (en-GB).
source share