Skip to main content

ceil

1. CEIL Function

The CEIL function in H2 database is used to round a number up to the nearest integer or specified decimal place.

2. Syntax

The syntax for the CEIL function in H2 database is as follows:

CEIL(number [, decimal_places])

Arguments

  • number: The number that needs to be rounded up. It can be an integer, decimal, or a column name.
  • decimal_places (optional): The number of decimal places to round up to. If not specified, the number will be rounded up to the nearest integer.

Return

  • The CEIL function returns the rounded-up value of the given number.

3. Notes

  • The CEIL function always rounds up the number, even if the fractional part is less than 0.5.
  • If the input number is not a valid numeric value or exceeds the numeric range, the CEIL function will return NULL.
  • When the decimal_places argument is provided, the CEIL function will round up the number to the specified decimal place. If the decimal_places argument is negative, the function will round up to the nearest 10, 100, etc.
  • Take care to use the correct syntax and data types when using the CEIL function to avoid errors.

4. Examples

Here are a few examples demonstrating the usage of the CEIL function in H2 database:

Example 1 - Rounding up a decimal number:

SELECT CEIL(3.14) AS result;

Output:

result
------
4

Example 2 - Rounding up a column of numbers:

CREATE TABLE prices (
id INT PRIMARY KEY,
price DOUBLE
);

INSERT INTO prices VALUES (1, 9.99), (2, 5.75), (3, 15.25);

SELECT id, price, CEIL(price) AS rounded_price
FROM prices;

Output:

id | price | rounded_price
---+-------+--------------
1 | 9.99 | 10
2 | 5.75 | 6
3 | 15.25 | 16

Example 3 - Rounding up to a specific decimal place:

SELECT CEIL(3.14159, 2) AS result;

Output:

result
------
3.15
  • floor - Round down to the nearest integer or specified decimal place.
  • round - Round to the nearest integer or specified decimal place.