Easy Tutorial
❮ Python Mongodb Insert Document Python String Lower ❯

Python math.trunc() Method

Python math Module

The math.trunc(x) method in Python returns the integer part of x, truncating the fractional part.

math.trunc(x) does not round the number up or down to the nearest integer; it simply removes the decimal part.

Syntax

The syntax for the math.trunc() method is as follows:

math.trunc(x)

Parameter Description:

Return Value

Returns an integer, representing the integer part of x.

Example

The following example returns the integer part of a number:

# Import the math package
import math

# Print the integer part
print(math.trunc(2.77))
print(math.trunc(8.32))
print(math.trunc(-99.29))

Output:

2
8
-99

Python math Module

❮ Python Mongodb Insert Document Python String Lower ❯