这三个函数对于初学者可能会经常的混淆,现在自己也正在学习,就做一个详细的记录。
Math.round()从字面意思上知道是周围的意思。如何得到一个double或者是float类型的数的周围的一个数呢?答案就是四舍五入。
如:doucument.write(Math.round(-5.3)) 结果为-5;而document.write(Math.round(-5.6)) 结果为-6.至于正整数的情况,就不做说明啦。
Math.floor(),floor()的意思是地板,所以该函数的意思为向下取整。
如:doucument.write(Math.round(-5.3)) 和document.write(Math.round(-5.6))都是-6
Math.ceil() 的意思是向上取整
如:doucument.write(Math.round(-5.3)) 和document.write(Math.round(-5.6))都是-5
本文详细解析了JavaScript中Math.round(), Math.floor() 和 Math.ceil()三个数学函数的区别与用法,并通过具体的示例来帮助读者理解如何正确使用这些函数进行数值处理。
3147

被折叠的 条评论
为什么被折叠?



