41

通过正则高效实现千位符(一行代码你敢信?)

 5 years ago
source link: https://juejin.im/post/5b766e7e6fb9a009b368bf37
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
怎么实现千位符 将数字转为可读性比较高的具有千位符是笔试/面试经常被问到的,实现方案也有很多种。 一般情况下,按照我们普通的想法,就是将数字转为字符串,然后使用字符串的substr、slice、substring来实现,从右到左,每隔三位插入一个",",eg:

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK