Home >Web Front-end >JS Tutorial >Detailed explanation of the method of comma-separated numerical thousandths using JS based on regular expressions
这篇文章主要介绍了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, '$1,');//使用正则替换,每隔三个数加一个',' 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!