Python math.trunc() Method

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

Visual Representation of Python math.trunc() Method

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.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.