如何将逗号添加到此javascript输出?

如何将逗号添加到此javascript输出?,javascript,Javascript,这是我的柜台: <script type="text/javascript"> $('.count').each(function () { $(this).prop('Counter',0).animate({ Counter: $(this).text() }, { duration: 4000, easing: 'swing', step: function (now

这是我的柜台:

  <script type="text/javascript">
  $('.count').each(function () {
      $(this).prop('Counter',0).animate({
          Counter: $(this).text()
      }, {
          duration: 4000,
          easing: 'swing',
          step: function (now) {
              $(this).text(Math.ceil(now));
          }
      });
  });
  </script>
这可能有效,但不确定如何将其合并到上述内容中:

function addCommas(nStr)

    {
        nStr += '';
        var x = nStr.split('.');
        var x1 = x[0];
        var x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }

你知道如何编辑这个吗?

这里有一个工作示例

函数格式编号(num){
常量regex=/\B(?=(\d{3})+(?!\d))/g;
return num.toString().replace(regex,,);
}
console.log(格式编号(1));
控制台日志(格式编号(100));
控制台日志(格式编号(1000));
console.log(格式编号(1000000))为什么不使用


console.log(新的Intl.NumberFormat('en-en')。格式(1234567890))
$(this).text(Math.ceil(now.tolocalstring())
?谢谢@jank,但我最终使用了上面的建议,只需要调整一行代码谢谢-事实上,我刚刚使用了>>>>$(this).text(Math.ceil(now.tolocalstring())
function addCommas(nStr)

    {
        nStr += '';
        var x = nStr.split('.');
        var x1 = x[0];
        var x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }