秋水的代码:<script>
function qswhDiv(p1,p2){
var t1=0,t2=0,r1,r2;
try{t1=p1.toString().split(".")[1].length}catch(e){}
try{t2=p2.toString().split(".")[1].length}catch(e){}
with(Math){
r1=p1*pow(10,t1)
r2=p2*pow(10,t2)
return (r1/r2)*pow(10,t2-t1);
}
}
alert(qswhDiv(19879,19.879))
alert(qswhDiv(19999,199.99))
</script>或者用vbscript alert (19879/19.879);
execScript('alert(19879/19.879)','vbscript')

解决方案 »

  1.   

    注意必须是js5.5以上(ie5.5以上即可)
    toFixed() Method
    Returns a string representing a number in fixed-point notation.numObj.toFixed([fractionDigits])Arguments
    numObjRequired A Number object.fractionDigitsOptional. Number of digits after the decimal point. Must be in the range 0 – 20, inclusive.Res
    The toFixed method returns a string representation of a number in fixed-point notation. The string contains one digit before the significand's decimal point, and must contain fractionDigits digits after it. If fractionDigits is not supplied or undefined, the toFixed method assumes the value is zero.Requirements
    Version 5.5