In this tutorial, we are going to learn about the math.trunc() method.
The method math.trunc() is used to truncate the float values. It will act as math.floor() method for positive values and math.ceil() method for negative values.
Example
# importing math module import math # floor value print(math.floor(3.5)) # trunc for positive number print(math.trunc(3.5))
Output
If you run the above code, then you will get the similar result as follows.
3 3
Example
# importing math module import math # ceil value print(math.ceil(-3.5)) # trunc for negative number print(math.trunc(-3.5))
Output
If you run the above code, then you will get the similar result as follows.
-3 -3
Conclusion
If you have any doubts in the tutorial, mention them in the comment section.