【Jquery】强制保留2位小数,四舍五入,不足两位小数自动在后面补上 .00

//使用  checknum(1.2233)
//强制保留2位小数,如:2,会在2后面补上00.即2.00    
function toDecimal2(x) {    var f = parseFloat(x);    if (isNaN(f)) {    return "0.00";    }    var f = Math.round(x*100)/100;    var s = f.toString();    var rs = s.indexOf('.');    if (rs < 0) {    rs = s.length;    s += '.';    }    while (s.length <= rs + 2) {    s += '0';    }    return s;    
}
//检测当前的数字
function checknum(_this){var num = $(_this).val();$(_this).val(toDecimal2(num));
}//限制数字的大小
function checknum100(_this,type){var num = $(_this).val();if(type == 1){if(num > 100){$(_this).val("99.99");}else{$(_this).val(toDecimal2(num));}}else{if(num > 99999){$(_this).val("99999.00");}else{$(_this).val(toDecimal2(num));}}
}

【Jquery】强制保留2位小数,四舍五入,不足两位小数自动在后面补上 .00

//使用  checknum(1.2233)
//强制保留2位小数,如:2,会在2后面补上00.即2.00    
function toDecimal2(x) {    var f = parseFloat(x);    if (isNaN(f)) {    return "0.00";    }    var f = Math.round(x*100)/100;    var s = f.toString();    var rs = s.indexOf('.');    if (rs < 0) {    rs = s.length;    s += '.';    }    while (s.length <= rs + 2) {    s += '0';    }    return s;    
}
//检测当前的数字
function checknum(_this){var num = $(_this).val();$(_this).val(toDecimal2(num));
}//限制数字的大小
function checknum100(_this,type){var num = $(_this).val();if(type == 1){if(num > 100){$(_this).val("99.99");}else{$(_this).val(toDecimal2(num));}}else{if(num > 99999){$(_this).val("99999.00");}else{$(_this).val(toDecimal2(num));}}
}