JS实现千分位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="last3Month">12345555554</div> <br> <div id="lastMonth"></div> <br> <div id="lastWeek"></div> <script> window.onload = function(){ var last3Month = document.getElementById('last3Month').innerHTML; document.getElementById('lastMonth').innerHTML = getThousandNum(last3Month); }
//千分位加逗号 function getThousandNum(val){ var reg = /(?=(?!(\b))(\d{3})+$)/g; return val.indexOf('.') >= 0 ? val.split('.')[0].replace(reg,',') + '.' + val.split('.')[1] : val.replace(reg,','); } </script> </body> </html>
其他版本的js实现千分位文章:https://www.cnblogs.com/lvmylife/p/8287247.html