例如,我想用 js 实现将数字 1000,显示成
1,000
的格式。
实现方法
let x = 100000000000000;
x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
> "100,000,000,000,000"
参考
https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript