当前位置:网站首页>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;
},
边栏推荐
猜你喜欢
Group DETR:分组一对多匹配是加速DETR收敛的关键
虹科技术|如何阻止供应链攻击?
2.1-----27. Remove elements
MT4/MQL4 entry to proficient foreign exchange EA tutorial Lesson 1 Getting to know MetaEditor
<爆>2022中文版-《海外博士申请指南-材料准备、时间线、套磁、面试及录取》免费分享
MT4/MQL4入门到精通EA教程第一课-MQL语言常用函数(一)OrderSend()函数
帮助安全红队取得成功的11条建议
gpio子系统和pinctrl子系统(上)
数仓第二篇: 数据模型(维度建模)
pytorch相关知识点总结
随机推荐
Group DETR:分组一对多匹配是加速DETR收敛的关键
composer的使用记录
企业面临的五大数据安全挑战
jmeter的websocket插件安装和使用方法
力扣刷题记录9.1-----24. 两两交换链表中的节点
【HNUMSC】C language second lecture
虹科技术|如何阻止供应链攻击?
Etcd realize large-scale application service management of actual combat
MT4/MQL4入门到精通EA课程第二课-常用的功能函数
如何保护智能家居避免黑客攻击
MT4/MQL4入门到精通外汇EA教程第一课 认识MetaEditor
2022/8/8 比赛思维+状压dp
程序员的日常生活 | 每日趣闻
2.1-----27. Remove elements
The last exam before the NPDP revision!caution
数据库设计的总结
Summary of pytorch related knowledge points
The 7 taboos of time management summarized by the postgraduate students, how many have you won?
【AspNetCore】实现JWT(使用Microsoft.AspNetCore.Authentication.JwtBearer)
php过滤特殊字符(仅保留中文、字母、数字、下划线)