js金额增加千分号

 //千分号分隔符
    micrometerHandle(num){
      //保留两位小数(不用可以删除)
      num = num.toFixed(2);
      
      return num && (num.toString().indexOf('.') != -1 ? num.toString().replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
        return $1 + ",";
     }) : num.toString().replace(/(\d)(?=(\d{3}))/g, function($0, $1) {
         return $1 + ",";
     }));
    }

 

posted @ 2022-08-03 16:27  花田007  阅读(139)  评论(0编辑  收藏  举报