XIN'BOLG

导航

4日6日--Math的常用方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Math的常用方法1</title>
    <script type="text/javascript">
        var n=-10;
        console.log(Math.abs(n));//10
        console.log(Math.pow(n,2));//100
        console.log(Math.sqrt(25));//5
        //3次方根:8的1/3次方
        console.log(Math.pow(8,1/3));
        var ret=Math.sin(Math.PI/6)
        console.log(ret.toFixed(3));//保留小数点后尾数,返回string
    </script>
</head>
<body>
    
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Math的常用方法2</title>
    <script type="text/javascript">
        var n=prompt("pls input:")*1;
        var ret=Math.floor(n);
        console.log("floor:"+ret);
        ret=Math.ceil(n);
        console.log("ceil:"+ret);
        ret=Math.round(n);
        console.log("round:"+ret);
    </script>
</head>
<body>
    
</body>
</html>

 

posted on 2017-04-06 15:00  XIN'BOLG  阅读(67)  评论(0编辑  收藏  举报