Math.round(),Math.ceil(),Math.floor()的区别转自达哥

编程入门 行业动态 更新时间:2024-10-08 06:29:48

Math.round(),Math.ceil(),Math.floor()的区别<a href=https://www.elefans.com/category/jswz/34/1767367.html style=转自达哥"/>

Math.round(),Math.ceil(),Math.floor()的区别转自达哥

1.Math.round():根据“round”的字面意思“附近、周围”,可以猜测该函数是求一个附近的整数,看下面几个例子就明白。

小数点后第一位<5 正数:Math.round(11.46)=11 负数:Math.round(-11.46)=-11 小数点后第一位>5 正数:Math.round(11.68)=12 负数:Math.round(-11.68)=-12 小数点后第一位=5 正数:Math.round(11.5)=12 负数:Math.round(-11.5)=-11 总结:(小数点后第一位)大于五全部加,等于五正数加,小于五全不加。 2.Math.ceil():根据“ceil”的字面意思“天花板”去理解; 例如: Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=12 Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-11 3.Math.floor():根据“floor”的字面意思“地板”去理解; 例如: Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=11 Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-12

更多推荐

Math.round(),Math.ceil(),Math.floor()的区别转自达哥

本文发布于:2024-02-07 07:14:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753760.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转自   区别   Math   ceil   floor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!