pyspark.sql.functions.floor#

pyspark.sql.functions.floor(col, scale=None)[source]#

Computes the floor of the given value.

Added in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
colColumn or column name

The target column or column name to compute the floor on. A column that evaluates to a numeric.

scaleColumn or int, optional

An optional parameter to control the rounding behavior. A column that evaluates to an integer. Must be a constant.

Added in version 4.0.0.

Returns:
Column

nearest integer that is less than or equal to given value. Returns a column that evaluates to a long or decimal.

Examples

Example 1: Compute the floor of a column value

>>> import pyspark.sql.functions as sf
>>> spark.range(1).select(sf.floor(sf.lit(2.5))).show()
+----------+
|FLOOR(2.5)|
+----------+
|         2|
+----------+

Example 2: Compute the floor of a column value with a specified scale

>>> import pyspark.sql.functions as sf
>>> spark.range(1).select(sf.floor(sf.lit(2.1267), sf.lit(2))).show()
+----------------+
|floor(2.1267, 2)|
+----------------+
|            2.12|
+----------------+