Math类的round方法小解

    在Math类中有三个关于“四舍五入”的静态方法(ceil,floor,round):

    ① Math.ceil(number)

        向上取整,Math.ceil(11.2) 结果:12              Math.ceil(11.6) 结果:12

                      Math.ceil(-11.2) 结果:-11            Math.ceil(-11.6) 结果:-11

    ② Math.floor(number)

       向下取整, Math.floor(11.2) 结果11              Math.floor(11.6) 结果11

                      Math.floor(-11.2)结果-12             Math.floor(-11.6)结果-12

     ③Math.round(number) = Math.floor(x+0.5)

        ”四舍五入“:Math.round(11.2) 结果11          Math.round(11.6) 结果12

                          Math.round(-11.2) 结果-11      Math.round(-11.6) 结果-12

原文地址:https://www.cnblogs.com/shuaiandjun/p/5428637.html