js数字转千分位方法

该方法为js方法,主要是取余,能给3整除的就给加个,  我看网上的基本上都是使用的正则方法,正则我不想用
 
 testClick() {
      let num = 7654321654647567;
      num = num + '';
      let newNum = '';
      if (num.length > 3) {
        for (let index = 0; index < num.length; index++) {
          if (index % 3 == 0) {
            newNum = newNum + num.charAt(index) + ',';
          } else {
            newNum = newNum + num.charAt(index);
          }
        }
      }
      return newNum;
    },
posted @ 2021-12-03 17:00  hongwj  阅读(342)  评论(0编辑  收藏  举报