为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
向下取整floor(),JavaScript进阶篇教程-慕课网
章节
课签
笔记
占位
占位

向下取整floor()

floor() 方法可对一个数进行向下取整。

语法:

Math.floor(x)

参数说明:

注意:返回的是小于或等于x,并且与 x 最接近的整数。

我们将在不同的数字上使用 floor() 方法,代码如下:

<script type="text/javascript">
  document.write(Math.floor(0.8)+ "<br>")
  document.write(Math.floor(6.3)+ "<br>")
  document.write(Math.floor(5)+ "<br>")
  document.write(Math.floor(3.5)+ "<br>")
  document.write(Math.floor(-5.1)+ "<br>")
  document.write(Math.floor(-5.9))
</script>

运行结果:

0
6
5
3
-6
-6

 

 

任务

补充右边编辑器在script标签内,使用floor()方法,计算3.3、-0.1、-9.9、8.9值。

?不会了怎么办

floor()向下取整计算,它返回的是大于或等于的值

||

写笔记

公开笔记
提交
||

请验证,完成请求

由于请求次数过多,请先验证,完成再次请求

收藏课程后,能更快找到我哦~

使用 Ctrl+D 可将课程添加到书签

举报

0/150
提交
取消