Skip to main content

floor

1. FLOOR Function

The FLOOR function in H2 database is used to round down a numeric value to the nearest integer that is less than or equal to the given value.

2. Syntax

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

FLOOR(value)

Arguments

  • value: The numeric value that needs to be rounded down. It can be of any numeric data type.

Return

  • The FLOOR function returns the rounded down value as an integer.

3. Notes

  • The FLOOR function in H2 database always returns an integer value.
  • If the input value is already an integer, the FLOOR function will return the same value.
  • If the input value is NULL, the FLOOR function will also return NULL.

4. Examples

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

Example 1 - Rounding down a decimal value:

SELECT FLOOR(3.7) AS rounded_value;

Output:

rounded_value
-------------
3

Example 2 - Rounding down a negative value:

SELECT FLOOR(-2.5) AS rounded_value;

Output:

rounded_value
-------------
-3

Example 3 - Rounding down a column of values:

CREATE TABLE numbers (
id INT PRIMARY KEY,
value DOUBLE
);

INSERT INTO numbers VALUES (1, 4.8), (2, 2.3), (3, 9.9);

SELECT id, value, FLOOR(value) AS rounded_value
FROM numbers;

Output:

id | value | rounded_value
---+-------+---------------
1 | 4.8 | 4
2 | 2.3 | 2
3 | 9.9 | 9
  • CEILING - Round up to the nearest integer
  • round - Round to the nearest integer