1 var xx = "d2182345.12".toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); 2 console.log(xx);
這個表達式 \B(?=(\d{3})+(?!\d))/g 超過三位小數,小數部分也會添加 逗號,加個負向先行斷言php
(?<!\.\d*)node
完善後: /(?<!\.\d*)\B(?=(\d{3})+(?!\d))/gspa
實驗平臺:http://www.runoob.com/try/runcode.php?filename=helloworld&type=nodejscode