Chạy thử Hàm toFixed() trong JavaScript
Chạy thử Hàm toFixed() trong JavaScript
Chạy thử Hàm toFixed() trong JavaScript
Tự code rồi chạy thử...
Chạy Thử
<!DOCTYPE html>
<html>
<head>
<title>Chạy thử Hàm toFixed() trong JavaScript</title>
</head>
<body>
<h1>Chạy thử Hàm toFixed() trong JavaScript</h1>
<p>Dùng để làm tròn số thập phân của một biến số sau đó trả kết quả về kiểu dữ liệu string, bạn có thể quy định phía sau dấu chấm có bao nhiêu số hoặc có thể bỏ dấu chấm:</p>
<script>
document.write("<b>toFixed() 35.727</b><br>");
var bienso = 35.727;
document.write(bienso.toFixed()+"<br>"); // Kết quả: 36
document.write(bienso.toFixed(0)+"<br>"); // Kết quả: 36
document.write(bienso.toFixed(1)+"<br>"); // Kết quả: 35.7
document.write(bienso.toFixed(2)+"<br>"); // Kết quả: 35.73
document.write(bienso.toFixed(3)+"<br>"); // Kết quả: 35.727
document.write(bienso.toFixed(4)+"<br>"); // Kết quả: 35.7270
document.write(bienso.toFixed(5)+"<br>"); // Kết quả: 35.72700
document.write("<b>toFixed() 35</b><br>");
var biensohai = 35;
document.write(biensohai.toFixed()+"<br>"); // Kết quả: 35
document.write(biensohai.toFixed(0)+"<br>"); // Kết quả: 35
document.write(biensohai.toFixed(1)+"<br>"); // Kết quả: 35.0
document.write(biensohai.toFixed(2)+"<br>"); // Kết quả: 35.00
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Chạy thử Hàm toFixed() trong JavaScript</title>
</head>
<body>
<h1>Chạy thử Hàm toFixed() trong JavaScript</h1>
<p>Dùng để làm tròn số thập phân của một biến số sau đó trả kết quả về kiểu dữ liệu string, bạn có thể quy định phía sau dấu chấm có bao nhiêu số hoặc có thể bỏ dấu chấm:</p>
<script>
document.write("<b>toFixed() 35.727</b><br>");
var bienso = 35.727;
document.write(bienso.toFixed()+"<br>"); // Kết quả: 36
document.write(bienso.toFixed(0)+"<br>"); // Kết quả: 36
document.write(bienso.toFixed(1)+"<br>"); // Kết quả: 35.7
document.write(bienso.toFixed(2)+"<br>"); // Kết quả: 35.73
document.write(bienso.toFixed(3)+"<br>"); // Kết quả: 35.727
document.write(bienso.toFixed(4)+"<br>"); // Kết quả: 35.7270
document.write(bienso.toFixed(5)+"<br>"); // Kết quả: 35.72700
document.write("<b>toFixed() 35</b><br>");
var biensohai = 35;
document.write(biensohai.toFixed()+"<br>"); // Kết quả: 35
document.write(biensohai.toFixed(0)+"<br>"); // Kết quả: 35
document.write(biensohai.toFixed(1)+"<br>"); // Kết quả: 35.0
document.write(biensohai.toFixed(2)+"<br>"); // Kết quả: 35.00
</script>
</body>
</html>
Chạy thử Hàm toFixed() trong JavaScript nằm trong bài viết Hàm toFixed() trong JavaScript