Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.trunc() Method

Python math.trunc() Method

Python math Module Python math Module

Python math.trunc(x) The method returns the truncated integer part of x, that is, the integer part with the fractional part ignored.

math.trunc(x) The method does not round a number up or down to the nearest integer, but simply removes the decimal part.

Syntax

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

math.trunc(x)

Parameter Description:

Return Value

Returns an integer int representing the integer part of x.

Example

The following example returns the integer part of numbers:

Example

Import the math package

import

math

Output the integer part

print

(

math

.

trunc

(

2.77

)

)

print

(

math

.

trunc

(

8.32

)

)

print

(

math

.

trunc

(

99.29

)

)

Output result:


2
8
-99

Python math Module Python math Module