首页 > 代码库 > toLocaleString

toLocaleString

记得以前有人问我如何格式化货币,我用数组加字符串操作然后实现了,今年不小心看微博,发现了更加简单的方法!!!

var num = 123456;
var options = {
   style:‘currency‘,
   currency:‘CNY‘  
};
num.toLocaleString(‘zh-CN‘,options);

  然后console出来了¥123,456.00;

  世间和平!

 

toLocaleString : dateObj.toLocaleString([locales[, options]])

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

 

  

toLocaleString