The Wayback Machine - https://web.archive.org/web/20241127033942/https://www.geeksforgeeks.org/python-math-floor-function/
Open In App

Python | math.floor() function

Last Updated : 16 Feb, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.floor() function returns the largest integer not greater than x. If number is already integer, same number is returned.

Syntax: math.floor(x)

Parameter:
x: This is a numeric expression.
Returns:  largest integer not greater than x.
Time Complexity: O(1)
Auxiliary Space: O(1)

Code #1: 

Python3




# Python code to demonstrate the working of floor()
   
# importing "math" for mathematical operations
import math
   
x = 33.7
   
# returning the floor of 33.7
print ("The floor of 33.7 is : ", end ="")
print (math.floor(x))


Output:

The floor of 33.7 is : 33

  Code #2: 

Python3




# Python code to demonstrate the working of floor()
   
# importing "math" for mathematical operations
import math
   
# prints the floor using floor() method
print ("math.floor(-13.1) : ", math.floor(-13.1))
print ("math.floor(101.96) : ", math.floor(101.96))


Output:

math.floor(-13.1) :  -14
math.floor(101.96) :  101


Similar Reads

Check the equality of integer division and math.floor() of Regular division in Python
For large quotients, floor division (//) doesn't seem to be necessarily equal to the floor of regular division (math.floor(a/b)) Examples: Input : 269792703866060742 // 3 Output : 89930901288686914 Input : math.floor(269792703866060742 / 3) Output : 89930901288686912 In the above examples, the output for floor division(//) is 89930901288686914 and
2 min read
floor() and ceil() function Python
The floor() function:floor() method in Python returns the floor of x i.e., the largest integer not greater than x. Syntax:import mathmath.floor(x)Parameter: x-numeric expression. Returns: largest integer not greater than x.Below is the Python implementation of floor() method: [GFGTABS] Python # Python program to demonstrate the use of floor() metho
4 min read
Python | Pandas DatetimeIndex.floor()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.floor() function floor the data to the specified frequency. The function takes the target frequency as input. It re
2 min read
Python | Pandas TimedeltaIndex.floor
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas TimedeltaIndex.floor() function floor all the values in the given TimedeltaIndex object to the specified frequency. Syntax : Time
2 min read
Python | Pandas Timestamp.floor
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Timestamp.floor() function return a new Timestamp floored to this resolution. The function takes the desired time series frequenc
2 min read
Python | Pandas Timedelta.floor()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Timedelta is a subclass of datetime.timedelta, and behaves in a similar manner. It is the pandas equivalent of python’s datetime.timedel
1 min read
Python - PyTorch floor() method
PyTorch torch.floor() method returns a new tensor which is floor of the elements of input, the largest integer less than or equal to each element. Syntax: torch.floor(input, out=None) Arguments input: This is input tensor. out: The output tensor. Return: It returns a Tensor. Let's see this concept with the help of few examples: Example 1: # Importi
1 min read
Ceil and floor of the dataframe in Pandas Python – Round up and Truncate
In this article, we will discuss getting the ceil and floor values of the Pandas Dataframe. First, Let's create a dataframe. Example: C/C++ Code # importing pandas and numpy import pandas as pd import numpy as np # Creating a DataFrame df = pd.DataFrame({'Student Name': ['Anuj', 'Ajay', 'Vivek', 'suraj', 'tanishq', 'vishal'], 'Marks': [55.3, 82.76,
2 min read
numpy.floor() in Python
The numpy.floor) is a mathematical function that returns the floor of the elements of array. The floor of the scalar x is the largest integer i, such that i <= x. Syntax : numpy.floor(x[, out]) = ufunc ‘floor’) Parameters : a : [array_like] Input array Return : The floor of each element. Code #1 : Working # Python program explaining # floor() fu
2 min read
How to get the floor, ceiling and truncated values of the elements of a numpy array?
In this article, let's discuss how to get the floor, ceiling, and truncated values of the elements of a Numpy array. First, we need to import the NumPy library to use all the functions available in it. This can be done with this import statement: import numpy as np Getting the floor value The greatest integer that is less than or equal to x where x
3 min read
Floor division in SQLAlchemy
In this article, we will see how to perform floor division in SQLAlchemy against a PostgreSQL database in python. Floor division is performed in different methods using different functions. Such kinds of mathematical operations are database-dependent. In PostgreSQL, floor division is performed using a function called div(). In SQLAlchemy, generic f
2 min read
Pandas Series dt.floor() | Round DateTime Values to Nearest Frequency
The dt.floor() method performs floor operation on the data to the specified frequency. This is useful when we want to round down the DateTime data to a specific frequency level, such as hourly (‘H’), daily (‘D’), monthly (‘M’), etc. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-12-31 08:45', '2019-1-1 12:30', '2008-02-2 10:30', '2010
2 min read
Python math.sqrt() function | Find Square Root in Python
sqrt() function returns square root of any number. It is an inbuilt function in Python programming language. In this article, we will learn more about the Python Program to Find the Square Root. sqrt() Function We can calculate square root in Python using the sqrt() function from the math module. In this example, we are calculating the square root
3 min read
Python math function | modf()
modf() function is an inbuilt function in Python that returns the fractional and integer parts of the number in a two-item tuple. Both parts have the same sign as the number. The integer part is returned as a float. Syntax : modf(number) Time Complexity: O(1) Auxiliary Space: O(1) Parameter : There is only one mandatory parameter which is the numbe
3 min read
Python math function | hypot()
hypot() function is an inbuilt math function in Python that return the Euclidean norm, [Tex]\sqrt{(x*x + y*y)} [/Tex]. Syntax : hypot(x, y) Parameters : x and y are numerical values Returns : Returns a float value having Euclidean norm, sqrt(x*x + y*y). Error : When more than two arguments are passed, it returns a TypeError. Note : One has to impor
2 min read
Python | math.fabs() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.fabs() function returns the absolute value of the number. Syntax: math.fabs(x) Parameter: x: This is a numeric expression. Returns: the absolute value of the number. Time Complexity: O(1) Auxiliary Space: O(1) Code #1: C/C++
1 min read
Python math function | copysign()
math.copysign() is a function exists in Standard math Library of Python. This function returns a float value consisting of magnitude from parameter x and the sign (+ve or -ve) from parameter y. Syntax : math.copysign(x, y) Parameters : x : Integer value to be converted y : Integer whose sign is required Returns : float value consisting of magnitude
1 min read
Python | math.ceil() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.ceil() function returns the smallest integral value greater than the number. If number is already integer, same number is returned. Syntax: math.ceil(x) Parameter: x: This is a numeric expression. Returns: Smallest integer no
1 min read
Python | math.factorial() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.factorial() function returns the factorial of desired number. Syntax: math.factorial(x) Parameter: x: This is a numeric expression. Returns: factorial of desired number. Time Complexity: O(n) where n is the input number. Auxi
2 min read
Python | math.copysign() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.copysign(a, b) function return a float with the magnitude (absolute value) of a but the sign of b. Syntax: math.copysign(a, b) Parameter: a, b: numeric values. Returns: Return absolute value of a but the sign of b. Code #1: #
1 min read
Python | math.gcd() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.gcd() function compute the greatest common divisor of 2 numbers mentioned in its arguments. Syntax: math.gcd(x, y) Parameter: x : Non-negative integer whose gcd has to be computed. y : Non-negative integer whose gcd has to be
2 min read
Python | math.cos() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.cos() function returns the cosine of value passed as argument. The value passed in this function should be in radians. Syntax: math.cos(x) Parameter: x : value to be passed to cos() Returns: Returns the cosine of value passed
2 min read
Python | math.tan() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.tan() function returns the tangent of value passed as argument. The value passed in this function should be in radians. Syntax: math.tan(x) Parameter: x : value to be passed to tan() Returns: Returns the tangent of value pass
1 min read
Python | math.sin() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.sin() function returns the sine of value passed as argument. The value passed in this function should be in radians. Syntax: math.sin(x) Parameter: x : value to be passed to sin() Returns: Returns the sine of value passed as
1 min read
Python - math.acos() function
Math module contains a number of functions which is used for mathematical operations. The math.acos() function returns the arc cosine value of a number. The value passed in this function should be in between -1 to 1. Syntax: math.acos(x) Parameter:This method accepts only single parameters. x :This parameter is the value to be passed to acos() Retu
2 min read
Python - math.acosh() function
Math module contains a number of functions which is used for mathematical operations. The math.acosh() function returns the hyperbolic arc cosine value of a number. The value passed in this function should be greater than or equal to 1. Syntax: math.acosh(x) Parameter:This method accepts only single parameters. x :This parameter is the value to be
2 min read
Python - math.asin() function
Math module contains a number of functions which is used for mathematical operations. The math.asin() function returns the arc sine value of a number. The value passed in this function should be between -1 to 1. Syntax: math.asin(x) Parameter:This method accepts only single parameters. x :This parameter is the value to be passed to asin() Returns:T
2 min read
Python - math.asinh() function
Math module contains a number of functions which is used for mathematical operations. The math.asinh() function returns the hyperbolic arc sine value of a number. Syntax: math.asinh(x) Parameter:This method accepts only single parameters. x :This parameter is the value to be passed to asinh() Returns:This function returns the hyperbolic arc sine va
1 min read
Python - math.atan() function
Math module contains a number of functions which is used for mathematical operations. The math.atan() function returns the arctangent of a number as a value. The value passed in this function should be between -PI/2 and PI/2 radians. Syntax: math.atan(x) Parameter:This method accepts only single parameters. x :This parameter is the value to be pass
2 min read
Python - math.atanh() function
Math module contains a number of functions which is used for mathematical operations. The math.atanh() function returns the hyperbolic arctangent of a number as a value. The value passed in this function should be between -0.99 to 0.99. Syntax: math.atanh(x) Parameter:This method accepts only single parameters. x :This parameter is the value to be
1 min read
Practice Tags :
three90RightbarBannerImg