round
Round the given value to scale decimal places using HALF_UP rounding mode if scale >= 0 or at integral part when scale < 0. Supports Spark Connect.
For the corresponding Databricks SQL function, see round function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.round(col=<col>, scale=<scale>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The target column or column name to compute the round on. |
|
| An optional parameter to control the rounding behavior. |
Returns
pyspark.sql.Column: A column for the rounded value.
Examples
Python
from pyspark.databricks.sql import functions as dbf
spark.range(1).select(dbf.round(dbf.lit(2.5))).show()
Output
+-------------+
|round(2.5, 0)|
+-------------+
| 3.0|
+-------------+
Python
from pyspark.databricks.sql import functions as dbf
spark.range(1).select(dbf.round(dbf.lit(2.1267), dbf.lit(2))).show()
Output
+----------------+
|round(2.1267, 2)|
+----------------+
| 2.13|
+----------------+