TypeScript TS 向上取整 向下取整 四舍五入 保留小数

  onLoad()
    {
    
    
        //向上取整数(小数舍去,正数部分+1)
        cc.log(Math.ceil(1.111));//=2
        cc.log(Math.ceil(1.6666));//=2
        //向下取整数(小数直接舍去)
        cc.log(Math.floor(1.111));//=1
        cc.log(Math.floor(1.666));//=1
        //四舍五入
        cc.log(Math.round(1.111));//1
        cc.log(Math.round(1.666));//2
        //保留小数
        cc.log(1.1111.toFixed());//1
        cc.log(1.1111.toFixed(2));//1.11
        cc.log(1.1111.toFixed(3));//1.111
        }

猜你喜欢

转载自blog.csdn.net/qq_36592993/article/details/114375386