日期:2014-05-16 浏览次数:20361 次
var num_s = "123213445654.6 "; alert(parseFloat(num_s).toLocaleString());
<html> <body> <table border="1" cellspacing="5" id="sp"> <tr><td>123454362670</td><td>3402.89</td><td>3402</td></tr></table> <script> function formatNumber(num){ if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){return num;} var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3; var re = new RegExp().compile("(\\d)(\\d{3})(,|$)"); while(re.test(b)) b = b.replace(re,"$1,$2$3"); return a +""+ b +""+ c; } function spl(){ var tdvalue=document.getElementById("sp").getElementsByTagName("td"); var std=""; var rstr=""; for(j=0;j<tdvalue.length;j++) { std=""; std=tdvalue[j]; rstr=formatNumber(std.innerHTML); std.innerHTML=rstr } } spl(); </script> </body> </html>