zxy0307's picture
Upload 3493 files
08aee07 verified
Raw History Blame Contribute Delete
894 Bytes
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Math对象</title>
</head>
<body>
<script>
/*
5. 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 之间的随机整数
*/
var ret = Math.floor(Math.random() * 100) + 1;
document.write(ret + "<br/>");
</script>
</body>
</html>