当前位置:网站首页>JS 实现千分位分隔符
JS 实现千分位分隔符
2022-08-09 02:22:00 【_格鲁特宝宝】
方法一:
没有小数位时
formatMoney(num) {
let reg=/\d{1,3}(?=(\d{3})+$)/g;
return (num + '').replace(reg, '$&,');
}方法二
有小数位时
formatThousand(money) {
let res = money.toString().replace(/\d+/, function(num){ // 先提取整数部分
return num.replace(/(\d)(?=(\d{3})+$)/g, function($1){
return $1+",";
});
})
return res;
},
边栏推荐
猜你喜欢

程序员的日常生活 | 每日趣闻

Likou Brush Question Record 6.1-----203. Remove linked list elements

The 7 taboos of time management summarized by the postgraduate students, how many have you won?

Electromagnetic radiation safety standards and detection methods

2.1-----27. Remove elements

gpio子系统和pinctrl子系统(下)

NPDP改版前最后一次考试!请注意

MT4/MQL4入门到精通EA教程第一课-MQL语言常用函数(一)OrderSend()函数

Line segment tree of knowledge

<爆>2022中文版-《海外博士申请指南-材料准备、时间线、套磁、面试及录取》免费分享
随机推荐
HCIP-R&S By Wakin自用笔记(2)OSPF之OSPF回顾、虚连接
The 7 taboos of time management summarized by the postgraduate students, how many have you won?
ApiFile配置环境
最强分布式锁工具:Redisson
电磁辐射安全标准及检测方法
显著性检验--学习笔记
连接数据库且在网页运行的RDLC
点击div内部默认文本被选中
Redis - 时间序列数据类型的保存方案和消息队列实现
mysql 5.7 入坑
力扣刷题记录5.1-----59. 螺旋矩阵 II
2022/8/8 Competition thinking + state pressure dp
全志平台双路LVDS配置
Mysql 5.7 into the pit
Use of torchversion.transforms
力扣刷题记录6.1-----203. 移除链表元素
mysql连接超过八小时报错
【AspNetCore】实现JWT(使用Microsoft.AspNetCore.Authentication.JwtBearer)
Educational Codeforces Round 132 (Rated for Div. 2)
YOLOV1详解——Pytorch版