Home >>Python math Module >Python math.trunc() Method

Python math.trunc() Method

Python math.trunc() Method

Python math.trunc() method in python is used to returns the real value truncated to an integral and a number (either an integer or a float).

Syntax:
math.tanh(x)

Parameter Values

Parameter Description
x It is required a number to remove the decimal part
Here is an Example of Python math.trunc() Method:

import math
print(math.trunc(1.87))
print(math.trunc(4.32))
print(math.trunc(-973.43))

Output:
1
4
-973
Example 2:

import math
a = 5
b = 5.13
c = -5
d = -5.54
e = 5.12
print("trunc(a): ", math.trunc(a))
print("trunc(b): ", math.trunc(b))
print("trunc(c): ", math.trunc(c))
print("trunc(d): ", math.trunc(d))
print("trunc(e): ", math.trunc(e))

Output:
trunc(a): 5
trunc(b): 5
trunc(c): -5
trunc(d): -5
trunc(e): 5

No Sidebar ads