您好,欢迎来到微智科技网。
搜索
您的当前位置:首页javascript中floor使用方法总结

javascript中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>

浏览器上运行效果如下:所有数字的输出都会小于或等于其最大整数。

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务