Math 객체의 round() 함수는 부동 소수점 난수를 받아들이고 가장 가까운 정수 값을 반환합니다.
- 주어진 숫자가 x.5 이상인 경우 이 함수는 다음 숫자(x+1)를 반환합니다.
- 주어진 숫자가 x.4 이하이면 이 함수는 이전 숫자(x-1)를 반환합니다.
- 주어진 숫자 자체가 정수인 경우 이 함수는 동일한 값을 반환합니다.
구문
구문은 다음과 같습니다.
Math.round();
예시
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var result = Math.round(2541.542);
document.write("Rounded value of the given number: "+result);
</script>
</body>
</html> 출력
Rounded value of the given number: 2542