Home >Web Front-end >JS Tutorial >Detailed explanation of the method of comma-separated numerical thousandths using JS based on regular expressions

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

怪我咯
怪我咯Original
2017-07-06 11:31:051828browse

这篇文章主要介绍了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>

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!

Statement:
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