JS实现数字格式千分位相互转换方法
作者:jingxian 时间:2023-08-31 08:24:48
实例如下:
/**
* 数字格式转换成千分位
*@param{Object}num
*/
function commafy(num){
if((num+"").Trim()==""){
return"";
}
if(isNaN(num)){
return"";
}
num = num+"";
if(/^.*\..*$/.test(num)){
varpointIndex =num.lastIndexOf(".");
varintPart = num.substring(0,pointIndex);
varpointPart =num.substring(pointIndex+1,num.length);
intPart = intPart +"";
var re =/(-?\d+)(\d{3})/
while(re.test(intPart)){
intPart =intPart.replace(re,"$1,$2")
}
num = intPart+"."+pointPart;
}else{
num = num +"";
var re =/(-?\d+)(\d{3})/
while(re.test(num)){
num =num.replace(re,"$1,$2")
}
}
return num;
}
/**
* 去除千分位
*@param{Object}num
*/
function delcommafy(num){
if((num+"").Trim()==""){
return"";
}
num=num.replace(/,/gi,'');
returnnum;
}
标签:数字格式,千分位
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#Web应用程序入门经典学习笔记之二
2024-06-05 09:28:00
Python简单实现区域生长方式
2023-08-08 12:07:38
Python和Pycharm 环境部署详细步骤
2022-09-25 02:25:45
![](https://img.aspxhome.com/file/2023/0/75260_0s.png)
一篇文章彻底搞懂python正则表达式
2021-02-10 13:16:19
![](https://img.aspxhome.com/file/2023/1/128221_0s.png)
Python程序员鲜为人知但你应该知道的17个问题
2021-06-14 11:37:14
一文详细谈谈GoLang的panic和error
2024-05-13 10:45:15
django 做 migrate 时 表已存在的处理方法
2022-02-14 16:11:53
mysql 中文乱码 解决方法集锦
2024-01-28 06:05:29
MySQL去重的方法整理
2024-01-27 07:04:42
Anaconda安装以及修改环境默认位置图文教程
2021-12-27 08:52:01
![](https://img.aspxhome.com/file/2023/3/101233_0s.png)
使用Python的package机制如何简化utils包设计详解
2021-08-14 04:21:06
Python动态生成多维数组的方法示例
2023-07-19 04:12:03
![](https://img.aspxhome.com/file/2023/1/90601_0s.png)
pandas按条件筛选数据的实现
2021-10-04 03:07:54
![](https://img.aspxhome.com/file/2023/4/105564_0s.png)
MySQL 函数过程递归
2008-07-25 19:32:00
python开发实时可视化仪表盘的示例
2022-04-23 15:33:44
![](https://img.aspxhome.com/file/2023/0/112370_0s.gif)
OpenCV 绘制同心圆的示例代码
2021-05-19 16:49:40
![](https://img.aspxhome.com/file/2023/8/115618_0s.jpg)
MySQL用户权限设置保护数据库安全
2024-01-16 09:03:07
Django利用AJAX技术实现博文实时搜索
2023-01-02 01:57:50
![](https://img.aspxhome.com/file/2023/3/80583_0s.jpg)
深入理解vue中的slot与slot-scope
2024-05-05 09:07:18
![](https://img.aspxhome.com/file/2023/0/130850_0s.png)
我们需要的是怎样的分页?
2007-09-28 20:24:00
![](https://img.aspxhome.com/file/UploadPic/20079/28/2007928202636587s.gif)