如何将1000000000.00转换成1,000,000,000.00
------解决方案--------------------
<SCRIPT LANGUAGE= "JavaScript ">
<!--
function formatNum(num, digit) //将数字转换成三位逗号分隔的样式
{
if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){alert( "wrong! "); 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 ");
if (c && digit && new RegExp( "^.(\\d{ "+ digit + "})(\\d) ").test(c)){
if (RegExp.$2> 4) c = (parseFloat(RegExp.$1)+1)/Math.pow(10, digit);
else c = ". "+ RegExp.$1;}
return a + " "+ b + " "+ (c+ " ").substr((c+ " ").indexOf( ". "));
}
alert(formatNum( "1000000000.00 "));
//-->
</SCRIPT>
------解决方案--------------------
---------------------------------------
// 表现形式增加逗号,这个可作为单独使用。
// Creation date: (2003-09-12)
// @author: ecc-wangdong,handong
// @version: 1.0
// @param:number
// @param说明:
// 需转换数值
//---------------------------------------
function displayComma(str) {
str = ' ' + str;
if ((str.indexOf( ". "))!= -1){
str1 = str.substring(0,str.indexOf( ". "));
str2 = str.substring(str.indexOf( ". "));
}else{
str1 = str;
}
if (str1.length > 3) {
var mod = str1.length % 3;
var output = (mod > 0 ? (str1.substring(0,mod)) : ' ');
for (i=0 ; i < Math.floor(str1.length / 3); i++) {
if ((mod == 0) && (i == 0))
output += str1.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output += ', ' + str1.substring(mod + 3 * i, mod + 3 * i + 3);
}
if ((str.indexOf( ". "))!= -1){
output = output + str2;
}
return (output);
}
else return str;
}