Python Tutorial Python Advanced Python References Python Libraries

Python math - trunc() Function



The Python math.trunc() function returns the truncated integer part of the argument. This method does NOT round the argument up or down to the nearest integer, but simply removes the decimals.

Syntax

math.trunc(x)  

Parameters

x Required. Specify a number.

Return Value

Returns the truncated integer part of the argument.

Example:

In the example below, trunc() function returns the truncated integer part of the given number.

import math

print(math.trunc(10.45))
print(math.trunc(50.55))
print(math.trunc(-25.45))
print(math.trunc(-75.55))

The output of the above code will be:

10
50
-25
-75

❮ Python Math Module

5