当前位置:网站首页>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;
},
边栏推荐
- Simple example of .reduce()
- Difference between KQL and Lucene
- [ANT]apache ant 安装说明
- 2022 PMP Project Management Certification Exam Registration Guide (1)
- ROS 、SLAM 学习 error整理
- Programmer's Daily Life | Daily Fun
- 【AspNetCore】实现JWT(使用Microsoft.AspNetCore.Authentication.JwtBearer)
- Use of torchversion.transforms
- Likou Brush Question Record 5.1-----59. Spiral Matrix II
- Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
猜你喜欢
mysql 5.7 入坑
[C language brush questions] Application of fast and slow pointers in linked lists
线段树知识整理
Codeforces Round #809 (Div. 2)A~D1
Force buckled brush problem record 7.1 -- -- -- -- -- 707. The design list
通过安装VNC服务器x11vnc(或vnc4server)和配置x11vnc.service实现远程通过VNC-Viewer访问VNC服务器。
9.1-----24. Swap the nodes in the linked list in pairs
ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
gpio子系统和pinctrl子系统(下)
边缘计算的三个关键好处
随机推荐
OpenMLDB + Jupyter Notebook:快速搭建机器学习应用
力扣刷题记录9.1-----24. 两两交换链表中的节点
C#计算SHA1加密和base64编码
软件开发之我的一点想法
Using ngrok on Raspberry Pi (Extra 2)
Analysis of when AuthenticationSuccessHandler is called after UsernameAuthenticationFilter is authorized successfully
MAYA发动机建模
2022眼康品牌加盟展,北京视力保健展,中国眼科医学技术峰会
物联网未来:未来五年的预期
【HNUMSC】C language second lecture
全志平台双路LVDS配置
力扣刷题记录7.1-----707. 设计链表
年金险的安全性怎么样啊?可靠吗?
2020.10.13开发日志
Mysql 5.7 into the pit
为什么应用程序依赖关系映射对于云迁移至关重要
2022/8/8 比赛思维+状压dp
点击div内部默认文本被选中
New Swagger3.0 tutorial, OAS3 quick configuration guide, to automate API interface documentation!
电磁辐射安全标准及检测方法