首页 > 编程 > JavaScript > 正文

javascript中floor使用方法总结

2019-11-19 12:10:42
字体:
来源:转载
供稿:网友

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>

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

以上就是本篇关于floor知识点的全部内容,感谢大家对武林网的支持。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表