toLocaleSting()

之前一直忽略了这一方法,直到前天的笔试题,两种方式实现如下功能。。。

1234567890→1,234,567,890

当时我的思路是这样的:1.字符串反转,插入逗号,再反转

           2.求余数,将字符串一分为二,对后面部分进行插入逗号,再字符串拼接

面试回来后,亮神给了一个很帅的方法:(1234567890).toLocaleString(3)

而梦神说,其实微软并不建议用3,而是使用.toLocaleString('zh-CN')。

其他:

http://www.w3school.com.cn/jsref/jsref_tolocalestring_number.asp

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation

原文地址:https://www.cnblogs.com/qianlegeqian/p/4094685.html