当前位置:网站首页>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>
边栏推荐
- AcWing 889. 01 sequence satisfying the condition (Cartland number)
- Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
- Several methods of creating thread classes
- 如何开始学剪辑?零基础详细解析
- [daily question in summer] first time, second time, deal!
- Causes of short circuit of conductive slip ring and Countermeasures
- 1076 Forwards on Weibo
- Principle, technology and implementation scheme of data consistency in distributed database
- [hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply
- Pico Neo3手柄抓取物体
猜你喜欢

Lock free concurrency of JUC (leguan lock)

LevelDB源码分析之memtable

CockroachDB 分布式事务源码分析之 TxnCoordSender

Usage and principle of synchronized

云原生存储解决方案Rook-Ceph与Rainbond结合的实践

Unity drags and modifies scene camera parameters under the editor

How to meet the requirements of source code confidentiality and source code security management

提高企业产品交付效率系列(1)—— 企业应用一键安装和升级

数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化

在Rainbond中一键部署高可用 EMQX 集群
随机推荐
Causes of short circuit of conductive slip ring and Countermeasures
And search: the suspects (find the number of people related to the nth person)
AcWing 884. Gauss elimination for solving XOR linear equations
Explanation of characteristics of hydraulic slip ring
Pico Neo3手柄抓取物体
複制寶貝提示材質不能為空,如何解决?
Precautions for use of conductive slip ring
AcWing 887. Finding combinatorial number III (Lucas theorem)
Global and Chinese market of search engine optimization (SEO) software 2022-2028: Research Report on technology, participants, trends, market size and share
复制宝贝提示材质不能为空,如何解决?
Pico neo3 handle grabs objects
eBPF Cilium实战(2) - 底层网络可观测性
LevelDB源码分析之memtable
Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
积分商城游戏能够给商家带来什么?怎么搭建积分商城?
每日一题-LeetCode1175-质数排列-数学
Use of STM32 expansion board temperature sensor and temperature humidity sensor
What can the points mall Games bring to businesses? How to build a points mall?
【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛