直接看程式碼吧
參數一:要保留小數位的數字
參數二:要保留的位數
function FormatNumber(src,nAfterDot) 🎜> var srcStr,nAfterDot;
var resultStr,nTen;
srcStr = "" srcStr "";
strLen = srcStr.length; if (dotPos == -1){
resultStr = srcStr ".";
for (i=0;i for (i=0;i for (i=0;i 🎜> }
}
else{
if ((strLen - dotPos - 1) >= nAfterDot){
for( j=0;j nTen = nTen*10;
}
resultStrStr 🎜> else{
resultStr = srcStr;
for (i=0;i
}
}
return resultStr;
}