-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_math_object.html
More file actions
53 lines (48 loc) · 1.94 KB
/
js_math_object.html
File metadata and controls
53 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!--
* @由于个人水平有限, 难免有些错误, 还请指点:
* @Author: cpu_code
* @Date: 2020-10-18 11:32:01
* @LastEditTime: 2020-10-18 11:38:07
* @FilePath: \web\javascript\js_js_math_objectmath\js_math_object.html
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
-->
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<title>math对象</title>
<script>
/*
Math:数学对象
1. 创建:
* 特点:Math对象不用创建,直接使用。 Math.方法名();
2. 方法:
random():返回 0 ~ 1 之间的随机数。 含0不含1
ceil(x):对数进行上舍入。
floor(x):对数进行下舍入。
round(x):把数四舍五入为最接近的整数。
3. 属性:
PI
*/
document.write(Math.PI + "<br>");
document.write(Math.random() + "<br>");
document.write(Math.round(3.14) + "<br>");
document.write(Math.ceil(3.14) + "<br>");
document.write(Math.floor(3.14) + "<br>");
/**
* 取 1~100之间的随机整数
* 1. Math.random()产生随机数:范围 [0,1)小数
* 2. 乘以 100 --> [0,99.9999] 小数
* 3. 舍弃小数部分 :floor --> [0,99] 整数
* 4. +1 -->[0,99] 整数 [1,100]
*/
var number = Math.floor((Math.random() * 100)) + 1;
document.write(number);
</script>
</head>
<body>
</body>
</html>