当前位置:网站首页>Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
2022-07-01 05:16:00 【i_ am_ a_ div_ Accumulate over time_】
demand : Digital amount , Display three digits with a comma . Both thousand One million One billion
Or it can be displayed with a comma according to a fixed number of digits .
Method 1:
<script type= "text/javascript">
// Keep three decimal places ,toLocaleString() The method can put a Number Object to a string in local format .
var num_s = "1232134456.546 ";
alert(parseFloat(num_s).toLocaleString());
</script>
Method 2: After the decimal point 00 The display is also saved
<script type="text/javascript">// There is no limit to the number of decimal places
function format_number(nStr ){
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/; //3 Is the number of digits in the interval
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>
边栏推荐
- Principle, technology and implementation scheme of data consistency in distributed database
- [daily question in summer] Luogu p1568 race
- Manually implement a simple stack
- Lock free concurrency of JUC (leguan lock)
- Pytoch (I) -- basic grammar
- 工业导电滑环的应用
- LeetCode522-最长特殊序列II-哈希表-字符串-双指针
- Daily question -leetcode1175- permutation of prime numbers - Mathematics
- Buffer stream and transform stream
- Pico Neo3手柄抓取物体
猜你喜欢

Mathematical knowledge: finding the number of divisors

Oracle views the creation time of the tablespace in the database

Go learning notes (5) basic types and declarations (4)

Pytoch (II) -- activation function, loss function and its gradient

Single page application

busybox生成的东西
![Is there any good website or software for learning programming? [introduction to programming]?](/img/ae/68a5880f313c307880ac80bd200530.jpg)
Is there any good website or software for learning programming? [introduction to programming]?
![[NLP Li Hongyi] notes](/img/8e/a51ca5eee638facd54270fb28d2fce.jpg)
[NLP Li Hongyi] notes

Principle, technology and implementation scheme of data consistency in distributed database

Distributed - summary list
随机推荐
Rust基础入门之变量绑定与解构
Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
FileInputStream
Causes of short circuit of conductive slip ring and Countermeasures
Global and Chinese markets of gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share
Distributed - summary list
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
複制寶貝提示材質不能為空,如何解决?
Flutter can refresh data every time the interface comes in
tar命令
Use of STM32 expansion board temperature sensor and temperature humidity sensor
JS random verification code
0xc000007b应用程序无法正常启动解决方案(亲测有效)
Daily question -leetcode1175- permutation of prime numbers - Mathematics
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
Global and Chinese market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数
