Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The ROUND function returns a numeric value rounded to the closest integer value or to the precision indicated by the optional second argument.
An Azure Cosmos DB system function that returns the number rounded to the closest integer.
Syntax
ROUND(<numeric_expr1> [, <numeric_expr2>])
Arguments
| Description | |
|---|---|
numeric_expr1 |
A numeric expression to round. |
numeric_expr2 |
(Optional) A numeric expression that sets the precision to round to. A positive value rounds to that many digits to the right of the decimal point, 0 rounds to the nearest integer, and a negative value rounds to the left of the decimal point. When omitted, the value is rounded to the nearest integer. |
Return types
Returns a numeric expression.
Examples
This section contains examples of how to use this query language construct.
Round numbers to nearest integer
In this example, positive and negative numbers are rounded to the nearest integer.
SELECT VALUE {
roundTwoPointFour: ROUND(2.4),
roundTwoPointSix: ROUND(2.6),
roundTwoPointFive: ROUND(2.5),
roundNegativeTwoPointFour: ROUND(-2.4),
roundNegativeTwoPointSix: ROUND(-2.6)
}
[
{
"roundTwoPointFour": 2,
"roundTwoPointSix": 3,
"roundTwoPointFive": 3,
"roundNegativeTwoPointFour": -2,
"roundNegativeTwoPointSix": -3
}
]
Round to a specified precision
The following example uses the optional second argument to control the rounding precision.
SELECT VALUE {
case1: ROUND(1234567, -2),
case2: ROUND(1234567, 0),
case3: ROUND(1234567, 2),
case4: ROUND(1234.567, -2),
case5: ROUND(1234.567, 0),
case6: ROUND(1234.567, 2)
}
[
{
"case1": 1234600,
"case2": 1234567,
"case3": 1234567,
"case4": 1200,
"case5": 1235,
"case6": 1234.57
}
]
Remarks
- This function benefits from the use of a range index. For more information, see range indexes.
- The rounding operation performed follows midpoint rounding away from zero. If the input is a numeric expression which falls exactly between two integers, the result is the closest integer value away from 0. For example
-6.5 to -7, -0.5 to -1, 0.5 to 1, 6.5 to 7.