ฟังก์ชัน trunc() ของออบเจกต์ Math ยอมรับตัวเลขและส่งคืนจุดรวม (ไม่รวมส่วนที่เป็นเศษส่วน) หากตัวเลขที่ระบุเป็นจำนวนเต็ม ฟังก์ชันนี้จะคืนค่าเดิม
ไวยากรณ์
ไวยากรณ์ของมันคือดังต่อไปนี้
Math.trunc();
ตัวอย่าง
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var result = Math.trunc(58.745);
document.write("Integral part of the given number: "+result);
</script>
</body>
</html> ผลลัพธ์
Integral part of the given number: 58