js实现千位分隔符分割

 function format(num) {
      var reg = /\d{1,3}(?=(\d{3})+$)/g;
      return (num + '').replace(reg, '$&,');
    }
    console.log(format(123456789));//123,456,789

  

posted @ 2021-02-08 14:56  流弊的小涛  阅读(62)  评论(0编辑  收藏  举报