trunc() in Python Last Updated : 20 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Truncate in Python There are many built-in modules in python. Out of these module there is one interesting module known as math module which have several functions in it like, ceil, floor, truncate, factorial, fabs, etc. Out of these functions there is an interesting function called truncate which behaves as a ceiling function for negative number and floor function for positive number. Time Complexity: O(1) Auxiliary Space: O(1) Python3 # Python program to show output of floor(), ceil() # truncate() for a positive number. import math print (math.floor(3.5)) # floor print (math.trunc(3.5)) # work as floor print (math.ceil(3.5)) # ceil Output: 3.0 3 4.0 In case of negative number Python3 # Python program to show output of floor(), ceil() # truncate() for a negative number. import math print (math.floor(-3.5)) # floor print (math.trunc(-3.5)) # work as ceil print (math.ceil(-3.5)) # ceil Output: -4.0 -3 -3.0 This is because the ceiling function is used to round up, i.e., towards positive infinity and floor function is used to round down, i.e., towards negative infinity. But the truncate function is used to round up or down towards zero.Diagrammatic representation of truncate function:- Comment More infoAdvertise with us Next Article C Vs Python K kartik Improve Article Tags : Python Practice Tags : python Similar Reads numpy.trunc() in Python The numpy.trunc() is a mathematical function that returns the truncated value of the elements of array. The trunc of the scalar x is the nearest integer i which, closer to zero than x. This simply means that, the fractional part of the signed number x is discarded by this function. Syntax : numpy.tr 2 min read Unpacking a Tuple in Python Tuple unpacking is a powerful feature in Python that allows you to assign the values of a tuple to multiple variables in a single line. This technique makes your code more readable and efficient. In other words, It is a process where we extract values from a tuple and assign them to variables in a s 2 min read Python | os.truncate() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.truncate() method in Python is used to truncate the file indicated by the spec 4 min read Python Traceback In Python, A traceback is a report containing the function calls made in your code at a specific point i.e when you get an error it is recommended that you should trace it backward(traceback). Whenever the code gets an exception, the traceback will give the information about what went wrong in the c 4 min read C Vs Python C: C is a structured, mid-level, general-purpose programming language that was developed at Bell Laboratories between 1972-73 by Dennis Ritchie. It was built as a foundation for developing the UNIX operating system. Being a mid-level language, C lacks the built-in functions that are characteristic o 4 min read Using C codes in Python | Set 1 Prerequisite: How to Call a C function in Python Let's discuss the problem of accessing C code from Python. As it is very evident that many of Pythonâs built-in libraries are written in C. So, to access C is a very important part of making Python talk to existing libraries. There is an extensive C p 4 min read Like