diveDylan / blog

My blog, detail is in the issues list
2 stars 0 forks source link

常用js小技巧 #37

Open diveDylan opened 4 years ago

diveDylan commented 4 years ago

数字格式化

// case 1     12345 ==> 12, 345
const formatNumber = number => String(number).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
// case 2    12345 ==> 12, 345
const formatNumber = number => number.toLocaleString('en-US')