-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.html
More file actions
42 lines (40 loc) · 976 Bytes
/
Math.html
File metadata and controls
42 lines (40 loc) · 976 Bytes
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Math</title>
</head>
<body>
<script type="text/javascript">
// Math 内置函数
// 1. Math.abs(x)
// 返回x的绝对值
var x = -10
console.log(Math.abs(x))
// 2. Math.round(x)
// 返回x四舍五入之后的整数值
x = 3.1415
console.log(Math.round(x))
// 3. Math.ceil(x)
// 返回x近似值,向上取整
x = 3.12
console.log(Math.ceil(x))
// 4. Math.floor(x)
// 返回x的近似值,向下取整
x = 3.75
console.log(Math.floor(x))
// 5. Math.max(x,y)
// 返回x,y中的最大值
// 6. Math.min(x,y)
// 返回x,y中的最小值
// 7. Math.random()
// 返回 0 - 1之间的随机数
console.log(Math.random()*10)
// 8. Math.sqrt(x)
// 返回x的平方根
console.log(Math.sqrt(5))
// 9. Math.sin(x) 返回x的正弦值
// 10.Math.cos(x) 返回x的余弦值
</script>
</body>
</html>