js 格式化数字,数字每隔三位加个逗号

 

js 格式化数字,数字每隔三位加个逗号

 

 

function formattedNumber(num) {
    var num = (num || 0).toString();
    var result = '';
    while (num.length > 3) {
        result = ',' + num.slice(-3) + result;
        num = num.slice(0, num.length - 3);
    }
    if (num) { result = num + result; }
    return result;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2021-09-21
  • 2022-12-23
  • 2021-11-25
  • 2022-01-15
猜你喜欢
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案