Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toLocaleString() doesn't work in Safari browser

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.

var test = 12300; 
console.log('test:'+test.toLocaleString());
 // 12,300 in IE,Chrome 
 // 12300 in Safari
like image 870
naanace Avatar asked Mar 05 '15 00:03

naanace


1 Answers

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

like image 101
Skitterm Avatar answered Nov 15 '22 18:11

Skitterm