码迷,mamicode.com
首页 > 编程语言 > 详细

javascript Math对象

时间:2018-04-15 13:29:51      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:lang   doc   ons   col   htm   style   lan   ack   asc   

 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>

 

javascript Math对象

标签:lang   doc   ons   col   htm   style   lan   ack   asc   

原文地址:https://www.cnblogs.com/knuzy/p/8846779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!