Jquery Math ceil()floor()round()比较与用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jquery Math ceil()floor()round()比较与用法相关的知识,希望对你有一定的参考价值。

Math.ceil():向上取值 如:Math.ceil(2.1) --  结果为  3

              Math.ceil(-2.1)  -- 结果为-2

        结论:正入 负舍

 

Math.floor(): 先下取值 入:

              Math.ceil(2.1) --  结果为  2

              Math.ceil(-2.1)  -- 结果为-3

 

        结论:和ceil()结论相反。 正舍 负入

Math.round:四舍五入

         Math.round(2.1) --  结果为  2

        Math.round(2.6) --  结果为  3

         Math.round(-2.1)  -- 结果为-2

        Math.round(-2.6)  -- 结果为-3

特别注意:

   Math.round(2.5)  --  3

   Math.round(-2.5)  --  (-2)

  结论 : 返回值的最接近的整数。

 

以上是关于Jquery Math ceil()floor()round()比较与用法的主要内容,如果未能解决你的问题,请参考以下文章

python中的math.ceil(x)和math.floor(x)

Math.ceil()Math.floor()和Math.round()

Javascript Math.ceil()与Math.round()与Math.floor()区别

Math中的floor,round和ceil方法总结

Math.floor,Math.ceil,Math.rint,Math.round用法

js中Math.roundparseIntMath.floor和Math.ceil小数取整总结(转)