Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the method of comma-separated numerical thousandths using JS based on regular expressions

怪我咯
Release: 2017-07-06 11:31:05
Original
1765 people have browsed it

这篇文章主要介绍了JS基于正则实现数字千分位用逗号分隔的方法,涉及javascript正则表达式操作数字的相关实现技巧,需要的朋友可以参考下

本文实例讲述了JS基于正则实现数字千分位用逗号分隔的方法。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>js千分位逗号隔开</title>
</head>
<body>
<script >
var a = 222122122.6754; 
var b = a.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, &#39;$1,&#39;);//使用正则替换,每隔三个数加一个&#39;,&#39; 
console.log(b)
</script>
</body>
</html>
Copy after login

The above is the detailed content of Detailed explanation of the method of comma-separated numerical thousandths using JS based on regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!