当前位置:网站首页>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;
},
边栏推荐
猜你喜欢

企业面临的五大数据安全挑战

SQLite切换日志模式优化

Electromagnetic radiation safety standards and detection methods

Force buckled brush problem record 7.1 -- -- -- -- -- 707. The design list

mysql 5.7 入坑

【izpack】使用izpack为你的程序提供安装程序封装

【云计算】XaaS最全介绍(按24字母合集):AaaS、BaaS、CaaS、DaaS、EaaS、FaaS、GaaS、HaaS、IDaaS…

eladmin container deployment super detailed process

最新工业界推荐系统数据集-召回排序模型原理、结构及代码实战整理分享

The first lesson of HNUMSC-C language
随机推荐
2020.10.13开发日志
中国SSD产业突围有多难?除了技术“瓶颈”还有哪里挑战?
Appium常用操作及H5页面元素定位
[ANT]apache ant 安装说明
显著性检验--学习笔记
JDBC technology (2) - set up common sql and configuration files
数仓第二篇: 数据模型(维度建模)
ROS2错误:不支持OpenGL 1.5 GLRenderSystem:: ci initialiseContext在C: \ \ ws \构建……
工具类:base64格式的数据与本地文件的相互转换
MT4 / MQL4 entry to the master of EA course lesson two - commonly used functions
How js implements array deduplication (7 kinds)
ApiFile配置环境
Flume (四) --------- Flume 企业开发案例
力扣刷题记录6.1-----203. 移除链表元素
MT4/MQ4L入门到精通EA教程第二课-MQL语言常用函数(二)-账户信息常用功能函数
<爆>2022中文版-《海外博士申请指南-材料准备、时间线、套磁、面试及录取》免费分享
【HNUMSC】C language second lecture
年金险的安全性怎么样啊?可靠吗?
Summary of Database Design
2022 Eye Health Brand Franchise Exhibition, Beijing Vision Care Exhibition, China Ophthalmology Technology Summit