这三个函数对于初学者可能会经常的混淆,现在自己也正在学习,就做一个详细的记录。
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