Python math.trunc ()วิธี การ
ตัวอย่าง
ค้นหาส่วนจำนวนเต็มของตัวเลขต่างๆ:
# Import math Library
import math
# Return the truncated integer
parts of
different numbers
print(math.trunc(2.77))
print(math.trunc(8.32))
print(math.trunc(-99.29))
ความหมายและการใช้งาน
เมธอดส่งคืน ส่วนmath.trunc()
จำนวนเต็มที่ตัดทอนของตัวเลข
หมายเหตุ:วิธีนี้จะไม่ปัดเศษตัวเลขขึ้น/ลงเป็นจำนวนเต็มที่ใกล้เคียงที่สุด แต่ให้ลบทศนิยมออก
ไวยากรณ์
math.trunc(x)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
x | Required. The number you want to remove the decimal part of. If the value is not a number, it returns a TypeError |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ค่า ที่int แทนส่วนจำนวนเต็มที่ตัดทอนของตัวเลข |
---|---|
เวอร์ชันหลาม: | 1.4 |