当前位置:网站首页>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;
},
边栏推荐
猜你喜欢
危化企业双预防机制数字化建设工作要求
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
Electromagnetic radiation safety standards and detection methods
Use of torchversion.transforms
[C language brush questions] Application of fast and slow pointers in linked lists
spdlog日志库的封装使用
HCIP-R&S By Wakin自用笔记(3)OSPF之各类LSA及LSA更新规则
史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!
OJ:L3-021 神坛 伪解 排序后遍历
SQLite切换日志模式优化
随机推荐
软件开发之我的一点想法
Likou Brush Question Record 8.1-----206. Reverse linked list
The first lesson of HNUMSC-C language
How js implements array deduplication (7 kinds)
2022中国眼博会,中国北京国际儿童青少年眼睛健康产业展览会
力扣刷题记录3.1-----977. 有序数组的平方
Use of torchversion.transforms
Group DETR:分组一对多匹配是加速DETR收敛的关键
【HNUMSC】C语言第二讲
年金险的安全性怎么样啊?可靠吗?
Likou Brush Question Record 6.1-----203. Remove linked list elements
力扣刷题记录--常用功能函数
【izpack】使用izpack为你的程序提供安装程序封装
UsernameAuthenticationFilter授权成功后调用AuthenticationSuccessHandler时的解析
虹科技术|如何阻止供应链攻击?
Etcd realize large-scale application service management of actual combat
The most fierce "employee" in history, madly complaining about the billionaire boss Xiao Zha: So rich, he always wears the same clothes!
The security of the pension insurance?Reliable?
Appium常用操作及H5页面元素定位
2020.12.4日志