JavaScript中的floor()方法是用于将作为参数传递的数字四舍五入到离向下方向最接近的整数,也就是朝向较小的值,本篇文章我们就来看看floor()方法的具体用法。 
floor()方法的基本语法: Math.floor( x ) ; x表示数字,返回小于或等于数字x的最大整数。 我们下面来看具体的示例 代码如下 <!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
document.write(Math.floor(-2)+"<br/>");
document.write(Math.floor(-2.56)+"<br/>");
document.write(Math.floor(2.56)+"<br/>");
document.write(Math.floor(7.2+9.3));
</script>
</body>
</html> 浏览器上运行效果如下:所有数字的输出都会小于或等于其最大整数。 
本篇文章到这里就全部结束了,更多精彩内容大家可以关注模板之家(www.mb5.com.cn)的其他相关栏目教程!!! 以上就是floor方法怎么使用的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |