Math函数

136 阅读1分钟
<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>
        // Math对象得属性

        // 圆周率
        var x=Math.PI;
        console.log(x);

        // Math对象得方法

        // Math.random(),返回0到1随机数

        // 找寻一组数据中最大的数
        // Math.max(11,55,99,33,77,55);

        // 找寻一组数据中最小的数
        // Math.min(11,55,99,33,55,77);

        // Math.ceil()向上取整
        var x=3.14;
        var y=Math.ceil(x);
        console.log(y);

        // Math.floor()向下取整
        var x=3.14;
        var y=Math.floor(x);
        console.log(y);

        // Math.round()四舍五入

        // Math.abs绝对值
    </script>
</body>
</html>