Cloud
round
The round() function rounds numbers using round half to even method (bankers rounding).
Arguments
-
number: The number to round. It can be positive, negative, or zero, and it can be an Integer or a Double Precision. -
scale: Optional. An integer specifying the number of decimal places to round to. When omitted, the function rounds to the nearest integer. A negative scale rounds to the left of the decimal point (for example,ROUND(1234, -2)returns1200).
Examples
Round to integer
In this example, the function rounds decimal numbers to integers:
SELECT
round(28.11) AS "round(28.11)",
round(12.51) AS "round(12.51)",
round(-9.11) AS "round(-9.11)",
round(102.5) AS "round(102.5)",
round(101.5) AS "round(101.5)",
round(-40.51) AS "round(-40.51)";
The query will return the nearest integer for all provided values.
round(28.11) | round(12.51) | round(-9.11) | round(102.5) | round(101.5) | round(-40.51)
--------------+--------------+--------------+--------------+---------------+---------------
28 | 13 | -9 | 102 | 102 | -41
Round to a specific number of decimal places
Use the two-argument form to specify the number of decimal places:
SELECT
round(3.14159, 2) AS "round(3.14159, 2)",
round(123.456, 1) AS "round(123.456, 1)",
round(99.995, 2) AS "round(99.995, 2)";
round(3.14159, 2) | round(123.456, 1) | round(99.995, 2)
-------------------+-------------------+------------------
3.14 | 123.5 | 100
Was this helpful?