1. Function: Rounding the floating-point number, take 2 digits after the decimal point
function var f = if (IsNaN (f)) { return ; } = Math. round (num*100)/100 return
document.write (todecimal (2.2291));
Results: 2.23
2. Function: Take 2 digits after the decimal point, not rounding
function get (num) { var str = num.substring (0,num.indexof (".") + 3); return str;} Document. Write (ToDecimal (2.2291));
Results: 2.22
3. Function: Take 2 digits after the decimal point, not rounding
function getnum (num) { var re =/([0-9]+\.[ 0-9]{2}) [0-9]*/; = Num.replace (Re, "$"); return anew;} Document. Write (Getnum ("23.456322")); Results:23.45
4. Function: Rounding the floating-point number, take 2 digits after the decimal point (need ie5.5+ only support)
var num=22.127456;d ocument. Write (num.tofixed (2))); Results:22.13
5. Function: Rounding the floating-point number, take 2 digits after the decimal point
function decimal (num,v) { var vv = Math. Pow(Ten,v); return Math. round (NUM*VV)/vv;} Document. Write (Decimal ("2.129", 2)); Results:2.13
JS Reserved N decimal places