3 Example(s) of JavaScript toFixed function
JavaScript toFixed function Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="convertToFixed()">Display the fixed number</button>
<p id="sample"></p>
<script>
function convertToFixed() {
var num = 6.76549;
var exp = num.toFixed(3);
document.getElementById("sample").innerHTML = exp;
}
</script>
</body>
</html>
JavaScript toFixed function Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="convertToFixed()">Display the fixed number</button>
<p id="sample"></p>
<script>
function convertToFixed() {
var num = 6.76549;
var exp = num.toFixed();
document.getElementById("sample").innerHTML = exp;
}
</script>
</body>
</html>
JavaScript toFixed function Example - 3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="convertToFixed()">Display the fixed number</button>
<p id="sample"></p>
<script>
function convertToFixed() {
var num = 1.23e+20;
var exp = num.toFixed(2);
document.getElementById("sample").innerHTML = exp;
}
</script>
</body>
</html>