«

Math的ceil&floor方法

yang 发布于 阅读:409 JS基础阶段


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let num = -9.99;
            // Math.ceil() 向上取整
            console.log(Math.ceil(num)); // -9
            let num2 = 6.999;
            // Math.floor() 向下取整
            console.log(Math.floor(num2)); // 6

            let arr = [10, 20, -19, 99, 88];
            console.log(...arr); // 10 20 -19 99 88,外挂:ES6展开运算符【了解】
            // Math.max() 求最大值
            console.log(Math.max(...arr));
            // Math.min() 求最小值
            console.log(Math.min(10, 20, -19, 99, 88));
        </script>
    </body>
</html>

Math的ceil&floor方法

版权所有:微4e
文章标题:Math的ceil&floor方法
除非注明,文章均为 微4e 原创,请勿用于任何商业用途,禁止转载

推荐阅读:


扫描二维码,在手机上阅读
请先 登录 再评论