<<<<<<< HEAD round | H2 | SQLDoc
Skip to main content

round

1. ROUND Function

======= round | H2 Function | SQLDoc

round

1. ROUND Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The ROUND function in H2 database is used to round a numeric value to a specified number of decimal places.

2. Syntax

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

ROUND(value, decimal_places)

Arguments

  • value: The numeric value that needs to be rounded.
  • decimal_places: The number of decimal places to which the value should be rounded. It should be an integer value.

Return

  • The ROUND function returns the rounded value.

3. Notes

  • The ROUND function in H2 database performs rounding according to the standard rounding rules. If the decimal part is exactly halfway between two possible rounded values, the result is rounded to the nearest even number.
  • If the input value or decimal_places is not a number or exceeds the numeric range, the ROUND function will return NULL.
  • Be cautious while rounding very large or very small values, as precision loss can occur.

4. Examples

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

Example 1 - Rounding a value to 2 decimal places:

SELECT ROUND(3.14159, 2) AS rounded_value;

Output:

rounded_value
-------------
3.14

Example 2 - Rounding a column of values:

CREATE TABLE prices (
id INT PRIMARY KEY,
price DECIMAL(10, 2)
);

INSERT INTO prices VALUES (1, 9.99), (2, 19.99), (3, 24.49);

SELECT id, price, ROUND(price, 1) AS rounded_price
FROM prices;

Output:

id | price | rounded_price
---+-------+---------------
1 | 9.99 | 10.0
2 | 19.99 | 20.0
3 | 24.49 | 24.5
  • CEILING - Round up to the nearest integer
  • floor - Round down to the nearest integer