用逗号每3位分割数字JS代码 ,也就是人们常说的科学计算法

functionformatNum(strNum) {  

if(strNum.length <= 3)

{

return strNum;

}

if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(strNum))

{

return strNum;

}

vara = RegExp.$1, b = RegExp.$2, c = RegExp.$3;

var re = new RegExp();

re.compile("(\\d)(\\d{3})(,|$)");

while(re.test(b)) {

b = b.replace(re, "$1,$2$3");

}

return a +""+ b +""+ c;

}



从格式化了的数字中删除逗号函数:

function clearNum(strNum) {

return strNum.replace(/,/g,"");

}


相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案