显示小数点后n位的简便写法 适用于显示价格:
function adv_format(iValue,n){
var sValue = Math.round(iValue * Math.pow(10,n)) + "";
var sPart1 = sValue.substr(0, sValue.length-n);
var sPart2 = sValue.substr(sValue.length-n);
return (sPart1 == "" ? "0" : sPart1) + "." + (sPart2 == "0" ? "00" : sPart2);
}
alert(adv_format(12.339999, 2))