日期:2014-05-16  浏览次数:20422 次

?(比如900000变成900,000)
?(比如900000变成900,000)

------解决方案--------------------
...来个 demo

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<!-- DW6 -->
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
<title> shawl.qiu template </title>
<style type= "text/css ">
/* <![CDATA[ */

/* ]]> */
</style>
<script type= "text/javascript ">
// <![CDATA[
if (navigator.appName== "Microsoft Internet Explorer ") {
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
//]]>
</script>
<script type= "text/javascript ">
// <![CDATA[
String.prototype.formatNumber=function(nLength, sSymbol){
if(!nLength) nLength=3;
if(!sSymbol) sSymbol= ', ';
return fNumFormat(this, nLength, sSymbol);
}
Number.prototype.formatNumber=function(nLength, sSymbol){
if(!nLength) nLength=3;
if(!sSymbol) sSymbol= ', ';
return fNumFormat(this, nLength, sSymbol);
}

function fNumFormat(nNumber, nLength, sSymbol){
if(!nLength)var nLength=3;
if(!sSymbol)var sSymbol= ', ';
if(!nNumber)return false;
nNumber+= ' ';
if(/\./.test(nNumber)){
nNumber=nNumber.replace(/(^.*?)\./,function($1,$2){
return padCma($2)+ '. '
});
} else nNumber=padCma(nNumber);
return nNumber;

function padCma(str){
var temp= ' ';
var nLen=str.length;
while(nLen> nLength){
temp=sSymbol+str.slice(nLen-=nLength, nLen+nLength)+temp;
}
if(nLen> 0&&nLen <=3) temp=str.slice(0, nLen)+temp;
return temp;
}
} // shawl.qiu code
onload =
function()
{
alert((99999999999+ " ").formatNumber());
alert((99999999999).formatNumber());
}
//]]>
</script>
</head>
<body>

</body>
</html>