HTML/Html-Javascript/17-数学对象.html
2023-05-01 19:37:40 +08:00

75 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//Math
// console.log(Math);
//00-随机数
//0 - 1的随机数(不包含0和1)
// console.log(Math.random());
// for (let index =0; index<10000;index++){
// let n = Math.random();
// if(n==0){
// console.log("n包含0");
// }
// if(n==1){
// console.log("n包含1");
// }
// }
//00-1 如何生产0-25的随机数 (不包含边界值)
//生成0-n的随机数 直接*n
// console.log(Math.random()*25);
//00-2 如何生成 5-25
//n-m的随机数
//Math.random()* (m-n) + n
// console.log(Math.random()*20 + 5);
//01-取整
//01-1 向上取整
// console.log(Math.ceil(1.1));
// console.log(Math.ceil(1.9));
//01-2 向下取整
// console.log(Math.floor(1.1));
// console.log(Math.floor(1.9));
//01-3 四舍五入
// console.log(Math.round(1.4));
// console.log(Math.round(1.5));
// console.log(Math.round(1.6));
//02-其他
// 绝对值
console.log(Math.abs(-99));
console.log(Math.abs(-99.222));
console.log(Math.abs(99));
console.log(Math.abs(99.222));
//保留小数
//针对number 结果为string
console.log(8.968).toFixed(2);
</script>
</body>
</html>