//将字母i全部替换成5
<script language="javascript">var txt = "sjfisjfisdjfijsidfjioalfjewofjjgs";alert(txt .replace(/i/g,"5"));</script> //只将第一个字母i替换成5<script language="javascript">var txt = "sjfisjfisdjfijsidfjioalfjewofjjgs";alert(txt .replace("i","5"));</script>//将15,255.55替换为15255.55
parseFloat(num2.split(",").join(""));
//直接使用 FormatNumber(srcStr,nAfterDot); 这个方法就行了。
function FormatNumber(srcStr,nAfterDot){ var srcStr,nAfterDot; var resultStr,nTen; srcStr = ""+srcStr+""; strLen = srcStr.length; dotPos = srcStr.indexOf(".",0); if (dotPos == -1){ resultStr = srcStr+"."; for (i=0;i<nAfterDot;i++){ resultStr = resultStr+"0"; } return resultStr; } else{ if ((strLen - dotPos - 1) >= nAfterDot){ nAfter = dotPos + nAfterDot + 1; nTen =1; for(j=0;j<nAfterDot;j++){ nTen = nTen*10; } resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen; return resultStr; } else{ resultStr = srcStr; for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){ resultStr = resultStr+"0"; } return resultStr; } } }