<!DOCTYPE html>
<html>
<head>
<title>Chạy thử Hàm parseFloat() trong JavaScript</title>
</head>
<body>
<h1>Chạy thử Hàm parseFloat() trong JavaScript</h1>
<p>Dùng để chuyển các ký tự trong chuỗi string thành số thực, nếu không chuyển được thành số thực thì trả về NaN, lưu ý số nguyên cũng là một dạng số thực:</p>
<script>
document.write(parseFloat("35.77abc")+"<br>"); // Kết quả: 35.77
document.write(parseFloat("abc35.77")+"<br>"); // Kết quả: NaN
document.write(parseFloat("35.77")+"<br>"); // Kết quả: 35.77
document.write(parseFloat(" 35.77 ")+"<br>"); // Kết quả: 35.77
document.write(parseFloat("35.66")+"<br>"); // Kết quả: 35.66
document.write(parseFloat("35.00")+"<br>"); // Kết quả: 35
document.write(parseFloat("35 36 37")+"<br>"); // Kết quả: 35
document.write(parseFloat("35.5 36.4 37.2")+"<br>"); // Kết quả: 35.5
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Chạy thử Hàm parseFloat() trong JavaScript</title>
</head>
<body>
<h1>Chạy thử Hàm parseFloat() trong JavaScript</h1>
<p>Dùng để chuyển các ký tự trong chuỗi string thành số thực, nếu không chuyển được thành số thực thì trả về NaN, lưu ý số nguyên cũng là một dạng số thực:</p>
<script>
document.write(parseFloat("35.77abc")+"<br>"); // Kết quả: 35.77
document.write(parseFloat("abc35.77")+"<br>"); // Kết quả: NaN
document.write(parseFloat("35.77")+"<br>"); // Kết quả: 35.77
document.write(parseFloat(" 35.77 ")+"<br>"); // Kết quả: 35.77
document.write(parseFloat("35.66")+"<br>"); // Kết quả: 35.66
document.write(parseFloat("35.00")+"<br>"); // Kết quả: 35
document.write(parseFloat("35 36 37")+"<br>"); // Kết quả: 35
document.write(parseFloat("35.5 36.4 37.2")+"<br>"); // Kết quả: 35.5
</script>
</body>
</html>