JavaScript中的Math.floor()函数

floor()Math对象的函数接受浮点数,并返回小于或等于给定数字的最大整数。如果给定的数字本身是整数,则此函数返回相同的值。

语法

它的语法如下

Math.floor(160)

示例

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result = Math.floor(160.98);
      document.write("Floor value: "+result);
   </script>
</body>
</html>

输出结果

Floor value: 160