import math
print(math.trunc(34.56)) # 34
print(math.trunc(34.21)) # 34
print(math.trunc(34.99)) # 34
print(math.trunc(34)) # 34
Using negative number
import math
print(math.trunc(-34.11)) # -34
print(math.trunc(-34.99)) # -34
print(math.trunc(-34)) # -34
Working with Large Numbers:
print(math.trunc(123456.789)) # Output: 123456
Using with Variables:
x = 45.67
print(math.trunc(x)) # Output: 45
import math
print(math.trunc(3.9)) # Output: 3
print(math.trunc(-3.9)) # Output: -3
print(math.floor(3.9)) # Output: 3
print(math.floor(-3.9)) # Output: -4
print(math.ceil(3.1)) # Output: 4
print(math.ceil(-3.1)) # Output: -3
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.