• 方法一:toLocaleString()

      1. function numFormat(num) {
      2. return num.toLocaleString()
      3. }
    • 方法二:正则

      1. function numFormat(num) {
      2. return num.toString().replace(/\d+/, n => {
      3. return n.replace(/(\d)(?=(\d{3})+$)/g, $1 => $1 + ',')
      4. })
      5. }