当前位置:网站首页>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>
边栏推荐
- Detailed explanation of distributed global unique ID solution
- Unity drags and modifies scene camera parameters under the editor
- Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
- Day 05 - file operation function
- AcWing 887. Finding combinatorial number III (Lucas theorem)
- Some common commands of podman
- Intelligent operation and maintenance: visual management system based on BIM Technology
- Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
- AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
- Explanation of characteristics of hydraulic slip ring
猜你喜欢

Detailed explanation of distributed global unique ID solution

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

Single page application

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

Distributed - summary list

Application and principle of ThreadPoolExecutor thread pool

Spanner 论文小结
![[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array](/img/22/606ff1e8dad3d5896b32d2146b0477.jpg)
[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array

Day 05 - file operation function

Use and principle of AQS related implementation classes
随机推荐
AcWing 884. Gauss elimination for solving XOR linear equations
Leetcode522- longest special sequence ii- hash table - String - double pointer
Actual combat: gateway api-2022.2.13
FileInputStream
【暑期每日一题】洛谷 P2026 求一次函数解析式
More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv. so‘.
LevelDB源码分析之memtable
在Rainbond中一键部署高可用 EMQX 集群
Copy baby prompt: material cannot be empty. How to solve it?
Pytoch (IV) -- visual tool visdom
Flutter 实现每次进来界面都刷新数据
使用 Nocalhost 开发 Rainbond 上的微服务应用
Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
【暑期每日一题】洛谷 P2637 第一次,第二次,成交!
如何开始学剪辑?零基础详细解析
Sqlplus connects using the instance name
Lock free concurrency of JUC (leguan lock)
【暑期每日一题】洛谷 P5886 Hello, 2020!
CockroachDB 分布式事务源码分析之 TxnCoordSender
AcWing 886. Finding combinatorial number II (pretreatment factorial)
