The math.trunc() method removes the fractional part of a number without rounding it.
It simply truncates off the decimal portion, regardless of whether the decimal part is greater or less than 0.5.
Syntax
import math
math.trunc(num)
Parameter
num(required): A number that you want to truncate.
Return value
It returns the truncated integer part of num.
Visual Representation
Example: How to Use math.trunc() Method
# Importing math library
import math
# Truncate different numbers
print(math.trunc(6.75))
print(math.trunc(3.754))
print(math.trunc(-1.27))
print(math.trunc(-4.445))
Output
6
3
-1
-4
That’s it.
Ankit Lathiya is a Master of Computer Application by education and Android and Laravel Developer by profession and one of the authors of this blog. He is also expert in JavaScript and Python development.