Retention and achieve decimal rounding

It comes with a function to achieve

var num = new Number(13.376954);
document.write (num.toFixed(2))

Custom functions for decimal and rounded reservations

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;
}
}

Guess you like

Origin www.cnblogs.com/derekhan/p/12124117.html