javascript将中国数字格式转换成欧式数字格式的简单实例
作者:jingxian 时间:2024-05-09 10:20:21
项目中遇到一个需求,要把中国式的显示阿拉伯数字的方式改为欧式的,即每三位显示,中间用逗号隔开,比如12345678改成12,345,678的显示方式,下面就是javascript代码的具体实现:
var iValue = 20002365879; //要转换的数字
var sValue = iValue+'';
var aValue = new Array();
var iNum = sValue.length%3;
var aResult; //转换结果
var index = 0;
if(sValue.length<=3){
console.log(sValue);
}else{
if(iNum == 0){
for(var i=0; i<sValue.length; i=i+3){
aValue[index] = sValue[i]+''+sValue[i+1]+''+sValue[i+2];
index++;
}
}else if(iNum == 1){
aValue[0] = sValue[0];
index = 1;
for(var i=1; i<sValue.length; i=i+3){
aValue[index] = sValue[i]+''+sValue[i+1]+''+sValue[i+2];
index++;
}
}else if(iNum == 2){
aValue[0] = sValue[0]+''+sValue[1];
index = 1;
for(var i=2; i<sValue.length; i=i+3){
aValue[index] = sValue[i]+''+sValue[i+1]+''+sValue[i+2];
index++;
}
}
aResult = aValue.join(',');
console.log(aResult.toString());//输出20,002,365,879
}
标签:javascript,转换,数字
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Opencv实现倾斜图片转正示例
2022-05-02 14:28:08
![](https://img.aspxhome.com/file/2023/3/70763_0s.jpg)
详解如何通过Python实现批量数据提取
2021-12-23 01:19:10
![](https://img.aspxhome.com/file/2023/2/86662_0s.png)
DB2和 Oracle的并发控制(锁)的比较
2009-02-28 10:29:00
Golang中字符串(string)与字节数组([]byte)一行代码互转实例
2023-09-17 14:37:07
![](https://img.aspxhome.com/file/2023/8/101038_0s.png)
Python实现学生管理系统并生成exe可执行文件详解流程
2023-03-11 04:52:42
![](https://img.aspxhome.com/file/2023/4/115414_0s.png)
xhEditor 免费的国产HTML在线编辑器
2022-05-25 23:05:32
浅析Python中线程以及线程阻塞
2022-03-06 22:14:23
![](https://img.aspxhome.com/file/2023/2/95902_0s.png)
一文了解MySQL二级索引的查询过程
2024-01-25 23:24:54
![](https://img.aspxhome.com/file/2023/5/122875_0s.png)
FP-growth算法发现频繁项集——构建FP树
2022-04-26 16:22:52
![](https://img.aspxhome.com/file/2023/1/133541_0s.png)
关于pytorch中网络loss传播和参数更新的理解
2023-08-06 05:29:09
![](https://img.aspxhome.com/file/2023/1/75351_0s.jpg)
Python Flask实现图片验证码与邮箱验证码流程详细讲解
2021-10-19 06:35:29
![](https://img.aspxhome.com/file/2023/1/92131_0s.png)
XHTML与HTML之间的7个区别
2009-05-20 10:13:00
keras自定义回调函数查看训练的loss和accuracy方式
2021-01-11 18:13:09
![](https://img.aspxhome.com/file/2023/4/128324_0s.jpg)
python中while循环语句用法简单实例
2021-12-03 22:34:44
Flask项目的部署的实现步骤
2023-08-11 17:59:58
![](https://img.aspxhome.com/file/2023/9/85319_0s.jpg)
解决在Python编辑器pycharm中程序run正常debug错误的问题
2023-09-09 09:58:39
![](https://img.aspxhome.com/file/2023/6/128206_0s.jpg)
apache配置虚拟主机的方法详解
2023-06-18 09:05:29
Python使用sax模块解析XML文件示例
2021-11-28 15:31:39
python字典多键值及重复键值的使用方法(详解)
2023-03-18 14:23:15
![](https://img.aspxhome.com/file/2023/3/131683_0s.jpg)
js 获取后台的字段 改变 checkbox的被选中的状态 代码
2024-04-22 22:33:40