js 浮点数四舍五入保留小数后指定位数
precision保留位数
function abandonNum(num,precision){
var source_precision=parseInt(precision);
var sourcenum=num.toString();
if(sourcenum.indexOf(".") != -1){
if(sourcenum.split(".")[1].length >source_precision ){
sourcenum = parseFloat(sourcenum).toFixed(source_precision);
return sourcenum;
}
} else{
return sourcenum;
}
return sourcenum;
}