ceil()
The ceil() function returns a number rounded up to the specified number of decimal digits.
Syntax
Parameters
NUM_EXPR- A numeric expression to round up. Supports 32-bit integer, 64-bit integer, 16-bit integer, 32-bit float, and 64-bit double types.
NUM_DIGITS- (Optional) The number of decimal digits to round up to. A positive value rounds up at the specified decimal place. Zero rounds up at the first decimal place. A negative value rounds up at the corresponding place above the decimal point. Defaults to
0if omitted.
Description
The ceil() function rounds up the value of NUM_EXPR at the position specified by NUM_DIGITS.
For integer types (32-bit integer, 64-bit integer, 16-bit integer), if NUM_DIGITS is 0 or greater, no rounding is needed and the input value is returned as-is. If NUM_DIGITS is negative, rounding is applied at the specified position and a 64-bit integer is returned.
For floating-point types (32-bit float, 64-bit double), the ceiling calculation is always applied.
Returns null if NUM_EXPR is null or not a number. Returns null if NUM_DIGITS is specified but is not an integer type (32-bit integer, 64-bit integer, or 16-bit integer).
Error codes
N/A
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Round up byte count to kilobytes.
table limit=5 WEB_APACHE_SAMPLE | eval result = ceil(bytes / 1024.0) | fields bytes, result -
Round up to one decimal place.
table limit=5 WEB_APACHE_SAMPLE | eval result = ceil(bytes / 1024.0, 1) | fields bytes, result -
Round up to the nearest hundred using a negative digit count.
table limit=5 WEB_APACHE_SAMPLE | eval result = ceil(bytes, -2) | fields bytes, result -
NULL input
json "{'val': null}" | eval result = ceil(val) | # result: null
Compatibility
The ceil() function is available since before Sonar 4.0.