snowflake.snowpark.functions.bround¶

snowflake.snowpark.functions.bround(col: Union[Column, str], scale: Union[Column, int]) → Column[source]¶

Rounds the number using HALF_TO_EVEN option. The HALF_TO_EVEN rounding mode rounds the given decimal value to the specified scale (number of decimal places) as follows: * If scale is greater than or equal to 0, round to the specified number of decimal places using half-even rounding. This rounds towards the nearest value with ties (equally close values) rounding to the nearest even digit. * If scale is less than 0, round to the integral part of the decimal. This rounds towards 0 and truncates the decimal places.

Note

1. The data type of the expression must be one of the data types for a fixed-point number.

  1. Data types for floating point numbers (e.g. FLOAT) are not supported with this argument.

  2. If the expression data type is not supported, the expression must be explicitly cast to decimal before calling.

Example

>>> import decimal
>>> data = [(decimal.Decimal(1.235)),(decimal.Decimal(3.5))]
>>> df = session.createDataFrame(data, ["value"])
>>> df.select(bround('VALUE',1).alias("VALUE")).show() # Rounds to 1 decimal place
-----------
|"VALUE"  |
-----------
|1.2      |
|3.5      |
-----------

>>> df.select(bround('VALUE',0).alias("VALUE")).show() # Rounds to 1 decimal place
-----------
|"VALUE"  |
-----------
|1        |
|4        |
-----------
Copy