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

posted @ 2016-04-24 22:32  帅LOVE俊  阅读(790)  评论(0编辑  收藏  举报