เพื่อหาจำนวนเต็มที่มากที่สุดแต่น้อยกว่าหรือเท่ากับตัวเลข ให้ใช้เมธอด Math.floor() ใน JavaScript
ตัวอย่าง
ลองรันโค้ดด้านล่างเพื่อหาจำนวนเต็มที่มากที่สุดแต่น้อยกว่าหรือเท่ากับตัวเลข
<html>
<head>
<title>JavaScript Math floor() Method</title>
</head>
<body>
<script>
var value = Math.floor(50.3);
document.write("First Value : " + value);
var value = Math.floor(20.7);
document.write("<br />Second Value : " + value);
var value = Math.floor(-5.8);
document.write("<br />Third Value : " + value);
var value = Math.floor(-3.1);
document.write("<br />Fourth Value : " + value);
</script>
</body>
</html>