原生
直接使用数字的 toLocaleString 方法, 就可以实现数字每 3 位添加一个逗号了, 缺点是针对浮点数, 只保留小数点后三位数并进行了四舍五入.
1 | function thousands(num){ |
字符串硬干
1 | const numToThousand = num => { |
正则
1 | function thousands(num){ |
字符串打散
1 | function thousands(num){ |
路漫漫其修远兮, 吾将上下而求索
直接使用数字的 toLocaleString 方法, 就可以实现数字每 3 位添加一个逗号了, 缺点是针对浮点数, 只保留小数点后三位数并进行了四舍五入.
1 | function thousands(num){ |
1 | const numToThousand = num => { |
1 | function thousands(num){ |
1 | function thousands(num){ |