javascript Math对象

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6 </head>
 7 <body>
 8     <script>
 9         var num = 1.4;
10         console.log(Math.abs(num));  //取绝对值:1.4
11         console.log(Math.floor(num));  //向下取整:1
12         console.log(Math.ceil(num));  //向上取整:2
13         console.log(Math.round(num));  //四舍五入取整,正数四舍五入,负数五舍六入:1
14         console.log(Math.random());  //随机数0-1
15         console.log(Math.random()*100);  //随机数0-100
16         console.log(Math.floor(Math.random()*100));  //0-100的随机数向下取整
17 
18         var num1 = -0.6;
19         console.log(Math.abs(num1));  //0.6
20         console.log(Math.floor(num1));  //-1
21         console.log(Math.ceil(num1));  //0
22         console.log(Math.round(num1));  //-1
23     </script>
24 </body>
25 </html>

 

posted @ 2018-04-15 11:54  叶子玉  阅读(135)  评论(0编辑  收藏  举报