zoukankan      html  css  js  c++  java
  • JS对象 向下取整floor() floor() 方法可对一个数进行向下取整。 语法: Math.floor(x)

    向下取整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值。


    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Math </title>
    <script type="text/javascript">
        document.write(Math.floor(3.3)+"<br/>");
        document.write(Math.floor(-0.1)+"<br/>");
        document.write(Math.floor(-9.9)+"<br/>");
        document.write(Math.floor(8.9));
    </script>
    </head>
    <body>
    </body>
    </html>




  • 相关阅读:
    全排列算法(java实现) 组合算法实现
    int -2147483648 ----- 2147483647
    Gradel 多渠道打包 代码混淆
    Android开发环境搭建
    自定义相册、九宫格显示图片
    新技术:retrofit
    新技术:dagger
    主流架构:MVVP
    GreenDao3.2的使用
    第三方框架:EventBus
  • 原文地址:https://www.cnblogs.com/yongbin668/p/5592751.html
Copyright © 2011-2022 走看看