使用HALF_UP舍入模式将给定值舍入为 scale 小数位数(如果 scale>= 0 或在整数部分为 0 时 scale< )。 支持 Spark Connect。
有关相应的 Databricks SQL 函数,请参阅 round 函数。
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.round(col=<col>, scale=<scale>)
参数
| 参数 | 类型 | Description |
|---|---|---|
col |
pyspark.sql.Column or column name |
要计算舍入的目标列或列名。 |
scale |
pyspark.sql.Column or int, optional |
用于控制舍入行为的可选参数。 |
退货
pyspark.sql.Column:舍入值的列。
例子
from pyspark.databricks.sql import functions as dbf
spark.range(1).select(dbf.round(dbf.lit(2.5))).show()
+-------------+
|round(2.5, 0)|
+-------------+
| 3.0|
+-------------+
from pyspark.databricks.sql import functions as dbf
spark.range(1).select(dbf.round(dbf.lit(2.1267), dbf.lit(2))).show()
+----------------+
|round(2.1267, 2)|
+----------------+
| 2.13|
+----------------+