自带函数实现
var num = new Number(13.376954);
document.write (num.toFixed(2))
自定义函数实现小数保留并四舍五入
function roundFun(numberRound,roundDigit) { //四舍五入,保留位数为roundDigit
if (numberRound>=0){
var tempNumber = parseInt((numberRound * Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);
return tempNumber;
} else{
numberRound1=-numberRound;
var tempNumber = parseInt((numberRound1 * Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);
return -tempNumber;
}
}