JS Math对象

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
console.log(Math.abs(-100)) // 100 #绝对值
console.log(Math.ceil(3.14)) //4 #向上取整
console.log(Math.floor(3.94)) //3 #向下取整
console.log(Math.round(3.94)) //4 #四舍五入
console.log(Math.round(3.14)) //3 #四舍五入

// 0-100随机浮点数
console.log(Math.round(Math.random()*100))



</script>
</head>
<body>
<h1>welcome to JS!</h1>
</body>
</html>

 

posted @ 2022-06-04 20:17  呼长喜  阅读(15)  评论(0编辑  收藏  举报