当前位置:网站首页>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>
边栏推荐
- Youqitong [vip] v3.7.2022.0106 official January 22 Edition
- Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
- Pytoch (I) -- basic grammar
- Use and principle of wait notify
- Distributed transactions - Solutions
- 【暑期每日一題】洛穀 P1568 賽跑
- Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
- [daily question in summer] function of rogu p3742 UMI
- LeetCode316-去除重复字母-栈-贪心-字符串
- CockroachDB 分布式事务源码分析之 TxnCoordSender
猜你喜欢

Pytoch (III) -- function optimization

Leetcode1497- check whether array pairs can be divided by K - array - hash table - count

Explanation of characteristics of hydraulic slip ring

Use of STM32 expansion board temperature sensor and temperature humidity sensor

Distributed architecture system splitting principles, requirements and microservice splitting steps

Use and principle of wait notify

Leetcode522- longest special sequence ii- hash table - String - double pointer

Vmware workstation network card settings and three common network modes
![[RootersCTF2019]babyWeb](/img/b4/aa8f8e107a9dacbace72d4717b1834.png)
[RootersCTF2019]babyWeb

Implementation of distributed lock
随机推荐
[summer daily question] Luogu p5886 Hello, 2020!
Serialization and deserialization of objects
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
How to traverse massive data in redis
Pytoch (II) -- activation function, loss function and its gradient
Spanner 论文小结
如何开始学剪辑?零基础详细解析
Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*
[daily question in summer] Luogu p2026 find the analytic formula of primary function
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
Like cloud functions
How to meet the requirements of source code confidentiality and source code security management
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
Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
Mathematical knowledge: finding the number of divisors
Application of industrial conductive slip ring
[daily question in summer] first time, second time, deal!
LeetCode522-最长特殊序列II-哈希表-字符串-双指针
How to start learning editing? Detailed analysis of zero basis
Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
