用js实现千位分隔符?

  function commafy(num) {
      return num && num
          .toString()
          .replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
              return $1 + ",";
          });
  }
  console.log(commafy(1234567.90)); //1,234,567.90

 

posted @ 2017-11-27 15:33  Samsara315  阅读(181)  评论(0编辑  收藏  举报