当前位置: 代码迷 >> 综合 >> JavaScrip -Math绝对值和三种取值方法案例
  详细解决方案

JavaScrip -Math绝对值和三种取值方法案例

热度:35   发布时间:2023-11-22 06:41:03.0
<!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>
  相关解决方案