JavaScript 将数字精确度定位,javascript取整

JavaScript 将数字精确度定位

num.fixed(n);

<script type="text/javascript">
function fixed(num){
  return num.toFixed(2);
}
alert(fixed(123.4));
</script>

 javascript取整

 1.丢弃小数部分,保留整数部分parseInt(5/2)      //2
2.向上取整,有小数,则整数部分加1Math.ceil(5/2)      //3
3.四舍五入Math.round(5/2)    //3
4.向下取整Math.floor(5/2)    //2
5.取余数 0%4   //0
    1%4   //1
    2%4   //2
    3%4   //3
    4%4   //0
    5%4   //1
原文地址:https://www.cnblogs.com/Decmber/p/4987650.html