round()
Returns a number rounded to the specified number of decimal digits.
Syntax
round(NUM_EXPR[, NUM_DIGITS])
Parameters
NUM_EXPR- The number to round. Supports 32-bit integer, 64-bit integer, 16-bit integer, 32-bit float, and 64-bit double types.
NUM_DIGITS- The number of digits to round to. Defaults to
0if omitted. A positive value specifies decimal places; a negative value specifies places above the decimal point.
Description
The round() function rounds NUM_EXPR to the number of digits specified by NUM_DIGITS.
The return type depends on the input type:
- For integer types (32-bit integer, 64-bit integer, 16-bit integer) with
NUM_DIGITSof 0 or greater, the input value is returned as-is. - For integer types with a negative
NUM_DIGITS, a 64-bit integer is returned. - For floating-point types (32-bit float, 64-bit double), a 64-bit double is returned.
Returns null in the following cases:
NUM_EXPRis null.NUM_EXPRis an unsupported type.NUM_DIGITSis specified but is not an integer type.
Error codes
N/A
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Round byte count to kilobytes.
table limit=5 WEB_APACHE_SAMPLE | eval result = round(bytes / 1024.0) | fields bytes, result -
Round to one decimal place.
table limit=5 WEB_APACHE_SAMPLE | eval result = round(bytes / 1024.0, 1) | fields bytes, result -
Round to the nearest hundred using a negative digit count.
table limit=5 WEB_APACHE_SAMPLE | eval result = round(bytes, -2) | fields bytes, result -
NULL input
json "{}" | eval r = round(null) | # r: null
Compatibility
The round() function is available since before Sonar 4.0.