round
function
Applies to: Databricks SQL Databricks Runtime
Returns the rounded expr
using HALF_UP
rounding mode.
Arguments
expr
: A numeric expression.targetScale
: AnINTEGER
constant expression. IftargetScale
is omitted the default is 0 (whole number).In Databricks SQL and Databricks Runtime 12.2 LTS and above: If
targetscale
is negative rounding is performed to positive powers of10
.
Returns
If expr
is DECIMAL
the result is DECIMAL
with a scale that is the smaller of expr
scale and targetScale
.
For all other numeric types, the result type matches expr
.
In HALF_UP
rounding, the digit 5 is rounded up.
For HALF_EVEN
rounding use the bround function.
Warning
In Databricks Runtime 12.2 LTS and below, and in Databricks Runtime if spark.sql.ansi.enabled is false
, an overflow does not cause an error but “wraps” the result instead.