当前位置:网站首页>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>
边栏推荐
- Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
- Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
- STM32 expansion board digital tube display
- Global and Chinese market of protection circuit modules 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of search engine optimization (SEO) software 2022-2028: Research Report on technology, participants, trends, market size and share
- Copier le matériel de conseils de bébé ne peut pas être vide, comment résoudre?
- 使用 Nocalhost 开发 Rainbond 上的微服务应用
- 3D建模與處理軟件簡介 劉利剛 中國科技大學
- 每日一题-LeetCode1175-质数排列-数学
- 【暑期每日一题】洛谷 P5886 Hello, 2020!
猜你喜欢

导电滑环短路的原因以及应对措施
![[summer daily question] Luogu p5886 Hello, 2020!](/img/ac/4be05f80aab7fb766674e6e2d16fbc.png)
[summer daily question] Luogu p5886 Hello, 2020!

Usage and principle of synchronized

Day 05 - file operation function

LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数

实战:redux的基本使用

Pytoch (III) -- function optimization

Thread process foundation of JUC

Copier le matériel de conseils de bébé ne peut pas être vide, comment résoudre?

在Rainbond中一键部署高可用 EMQX 集群
随机推荐
Several methods of creating thread classes
Global and Chinese markets for soft ferrite cores 2022-2028: Research Report on technology, participants, trends, market size and share
Data loading and preprocessing
如何选择导电滑环材料
Lock free concurrency of JUC (leguan lock)
【暑期每日一题】洛谷 P1568 赛跑
busybox生成的东西
Flutter can refresh data every time the interface comes in
Global and Chinese markets of gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share
How to select conductive slip ring material
AcWing 889. 01 sequence satisfying the condition (Cartland number)
Solution: drag the Xib control to the code file, and an error setvalue:forundefined key:this class is not key value coding compliant for the key is reported
积分商城游戏能够给商家带来什么?怎么搭建积分商城?
How to hide browser network IP address and modify IP internet access?
el-form表单新增表单项动态校验;el-form校验动态表单v-if不生效;
Simple read / write verification of qdatastream
AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
[RootersCTF2019]babyWeb
Manually implement a simple stack
Implementation of distributed lock
