toLocaleString() doesn't work in Safari browser

naanace picture naanace · Mar 5, 2015 · Viewed 8.2k times · Source

I used toLocaleString() method to input money comma in `javascript. But the problem is, IE and chrome browser result correctly except Safari browser. I delete cache several times but still doesn't work. Can you help? ;)

var test = 12300; 
console.log('test:'+test.toLocaleString());
 // 12,300 in IE,Chrome 
 // 12300 in Safari

Answer

Skitterm picture Skitterm · Jun 3, 2015

The issue here is that number.toLocaleString is implemented differently on different browsers. On Safari, it chooses not to display with the person-friendly formatting we're used to. It is supported on safari, but its implementation isn't the same as IE, Chrome, or Firefox. See this link: http://forums.asp.net/t/2031925.aspx?toLocaleString+function+is+inconsistent+with+browser+

Also, Safari doesn't support using the locale parameter with toLocaleString, in case you tried setting that: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString