当前位置:网站首页>数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
2022-07-01 05:07:00 【i_am_a_div_日积月累_】
需求:数字金额,按照三位一个逗号显示。既 千 百万 十亿
或者是按照固定的几位一个逗号展示。
方法1:
<script type= "text/javascript">
//保留三位小数,toLocaleString() 方法可把一个 Number 对象转换为本地格式的字符串。
var num_s = "1232134456.546 ";
alert(parseFloat(num_s).toLocaleString());
</script>
方法2:小数点后的00也会保存显示
<script type="text/javascript">// 小数点位不限制
function format_number(nStr ){
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/; //3就是间隔的位数
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
var a="53669988.000";
alert(format_number(a));
alert(format_number("wahh"));
alert(format_number(0));
alert(format_number(6698.0023));
</script>
边栏推荐
- [daily question in summer] Luogu p5740 [deep foundation 7. Example 9] the best student
- 【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
- 如何选择导电滑环材料
- Global and Chinese markets of InGaAs APD arrays 2022-2028: Research Report on technology, participants, trends, market size and share
- RuntimeError: “max_pool2d“ not implemented for ‘Long‘
- Leetcode316- remove duplicate letters - stack - greedy - string
- Simple read / write verification of qdatastream
- Pytorch convolution operation
- Global and Chinese market of 3D CAD 2022-2028: Research Report on technology, participants, trends, market size and share
- Basic skeleton of neural network nn Use of moudle
猜你喜欢

Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards

STM32扩展版 按键扫描

Detailed explanation of distributed global unique ID solution
![Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*

Pytoch (IV) -- visual tool visdom

Neural networks - use of maximum pooling

智慧运维:基于 BIM 技术的可视化管理系统

C read / write application configuration file app exe. Config and display it on the interface

LevelDB源码分析之memtable

Single page application
随机推荐
Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
Pico Neo3手柄抓取物体
线程安全问题
每日一题-LeetCode1175-质数排列-数学
缓冲流与转换流
Vmware workstation network card settings and three common network modes
Implementation of distributed lock
Unit testing with mongodb
Leetcode1497- check whether array pairs can be divided by K - array - hash table - count
Pytorch convolution operation
複制寶貝提示材質不能為空,如何解决?
[summer daily question] Luogu p5886 Hello, 2020!
LeetCode_ 35 (search insertion position)
AcWing 886. Finding combinatorial number II (pretreatment factorial)
QDataStream的簡單讀寫驗證
STM32 photoresistor sensor & two channel AD acquisition
导电滑环短路的原因以及应对措施
Use and modification of prior network model
Global and Chinese market of solder wire 2022-2028: Research Report on technology, participants, trends, market size and share
How to meet the requirements of source code confidentiality and source code security management
