js完成千位分隔符

function commafy(num) {
  num = num + '';
  var reg = /(-?\d+)(\d{3})/;

  if(reg.test(num)){
    num = num.replace(reg, '$1,$2');
  }

  return num;
}

commafy(1234);
    原文作者:Doyle
    原文地址: https://segmentfault.com/a/1190000002476290
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞