1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title></title>
6 <script type="text/javascript">
7 /*
8 * Math
9 * - Math和其他的对象不同,它不是一个构造函数,
10 * 它属于一个工具类不用创建对象,它里边封装了数学运算相关的属性和方法
11 * - 比如
12 * Math.PI 表示的圆周率
13 */
14
15 //console.log(Math.PI);
16
17 /*
18 * abs()可以用来计算一个数的绝对值
19 */
20 //console.log(Math.abs(-1));
21
22 /*
23 * Math.ceil()
24 * - 可以对一个数进行向上取整,小数位只有有值就自动进1
25 * Math.floor()
26 * - 可以对一个数进行向下取整,小数部分会被舍掉
27 * Math.round()
28 * - 可以对一个数进行四舍五入取整
29 */
30 //console.log(Math.ceil(1.1));
31 //console.log(Math.floor(1.99));
32 //console.log(Math.round(1.4));
33
34 /*
35 * Math.random()
36 * - 可以用来生成一个0-1之间的随机数
37 * - 生成一个0-10的随机数
38 * - 生成一个0-x之间的随机数
39 * Math.round(Math.random()*x)
40 *
41 * - 生成一个1-10
42 * - 生成一个x-y之间的随机数
43 * Math.round(Math.random()*(y-x)+x)
44 */
45 /*for(var i=0 ; i<100 ; i++){
46 //console.log(Math.round(Math.random()*10));
47 //console.log(Math.round(Math.random()*20));
48
49 //console.log(Math.round(Math.random()*9)+1);
50 //console.log(Math.round(Math.random()*8)+2);
51
52 //生成1-6之间的随机数
53 console.log(Math.round(Math.random()*5+1));
54 }*/
55
56 /*
57 * max() 可以获取多个数中的最大值
58 * min() 可以获取多个数中的最小值
59 */
60
61 var max = Math.max(10,45,30,100);
62 var min = Math.min(10,45,30,100);
63 //console.log(min);
64
65 /*
66 * Math.pow(x,y)
67 * 返回x的y次幂
68 */
69
70 //console.log(Math.pow(12,3));
71
72 /*
73 * Math.sqrt()
74 * 用于对一个数进行开方运算
75 */
76 console.log(Math.sqrt(2));
77
78 </script>
79 </head>
80 <body>
81 </body>
82 </html>