ในการรับจำนวนเต็มที่มากที่สุดซึ่งน้อยกว่าหรือเท่ากับตัวเลข ให้ใช้เมธอด 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>