<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// 绝对值
console.log('绝对值');
console.log(Math.abs(-1));
console.log(Math.abs(1));
console.log(Math.abs('-1')); //隐式转换
// 向下取整
console.log('向下取整');
console.log(Math.floor(1.1));
console.log(Math.floor(1.7));
// 向上取整
console.log('向上取整');
console.log(Math.ceil(1.1));
console.log(Math.ceil(1.9));
// 四舍五入
console.log('四舍五入');
console.log(Math.round(1.1));
console.log(Math.round(1.6));
console.log(Math.round(1.5));
console.log(Math.round(-1.5));
</script>
</head>
<body>
</body>
</html>
JavaScrip -Math绝对值和三种取值方法案例
最新推荐文章于 2025-02-23 23:29:50 发布