代码示例:(标识:jsck_round_1)
<!DOCTYPE html>
<html>
<body>

<p>单击该按钮可将数字 2.5 舍入为其最接近的整数。</p>

<button onclick="myFunction()">试一试</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = Math.round(2.5);
}
</script>

</body>
</html>
运行结果: