Number 객체의 toFixed() 함수는 소수점 이하 표시할 점의 수를 나타내는 숫자를 받아 그에 따라 현재 숫자를 표시합니다.
구문
구문은 다음과 같습니다.
num.toFixed(num);
예시
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
result = num.toFixed(4);
document.write("Fixed point notation of the given number is: " + result);
</script>
</body>
</html> 출력
Fixed point notation of the given number is: 3.1416
예시
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
document.write("Fixed point notation of the given number is: " + num.toFixed(4));
document.write("<br>");
var num = 2.13e+15;
document.write("Fixed point notation of the given number is: " + num.toFixed(4));
</script>
</body>
</html> 출력
Fixed point notation of the given number is: 3.1416 Fixed point notation of the given number is: 2130000000000000.0000