Number formating, spaces every 3 digits

2019-08-23 03:59发布

How can I change number without formating and decimal values (like: 125478521478) to string that has spaces every 3 digits (like: 24 148 147), it would have to convert ~100 of those numbers so I'm looking for efficient solution.

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-23 04:47

This script should help you. You can run this script in a loop for all the numbers. Considering 125478521478 as your number for demonstration. The code shall be as follows -

var yourNumber = "125478521478";
yourNumber  = yourNumber.toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, " ");

Hope it helps!

查看更多
登录 后发表回答