sum = "1234567890.99";sum = sum.split("").reverse().join("").replace(/(\d{3})(?=\d)/g, "$1,").split("").reverse().join("");
效率比较差,下面这个会更快一些while(sum.match(/\d{4}[,.]/)) sum=sum.replace(/(\d)(\d{3})([,.])/,"$1,$2$3")
记下记下。如果没有性能要求的话,还是我这种好写,只要在字符串后面拖个一长串就搞定啦~
Post a Comment
2 comments:
效率比较差,下面这个会更快一些
while(sum.match(/\d{4}[,.]/)) sum=sum.replace(/(\d)(\d{3})([,.])/,"$1,$2$3")
记下记下。如果没有性能要求的话,还是我这种好写,只要在字符串后面拖个一长串就搞定啦~
Post a Comment