自带函数实现

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

相关文章:

  • 2021-12-18
  • 2021-11-24
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2021-06-05
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
相关资源
相似解决方案