Dùng Math.round(x) làm tròn theo quy tắc: phần thập phân ≥ 0.5 thì lên, < 0.5 thì xuống.
Ví dụ
<html>
<head>
<title>Phương thức Math.round trong JavaScript</title>
</head>
<body>
<script>
document.write("round(0.5) = " + Math.round(0.5) + "<br>"); // 1
document.write("round(20.7) = " + Math.round(20.7) + "<br>"); // 21
document.write("round(20.3) = " + Math.round(20.3) + "<br>"); // 20
document.write("round(-20.3) = " + Math.round(-20.3)); // -20
</script>
</body>
</html>