Oracle ROUND(number) Function
Oracle ROUND(number) is a built-in function that rounds a given number to a given number of decimal places.
Oracle ROUND(number) syntax
Here is the syntax for the Oracle ROUND(number) function:
ROUND(number[, d])
Parameters
number-
Required. Numbers that need to be rounded.
d-
Optional. The number of decimal places to keep. The default value is 0. It can be any numeric data type or any non-numeric data type that can be implicitly converted to a numeric data type.
Return Value
The Oracle ROUND(number) function returns a rounded number. It is implemented using the following rules:
- If
numberis 0, thenROUNDalways returns 0, regardless whateverdis. - If
numberis negative, thenROUND(number, d)returns-ROUND(-number, d). - If
numberis positive, thenROUND(number, d)equals toFLOOR(number * POWER(10, d) + 0.5) * POWER(10, -d).
If any parameter is NULL, ROUND(number) will return NULL.
Oracle ROUND(number) Examples
Here are some examples that demonstrate the usage of the Oracle ROUND(number) function.
Basic Usage
SELECT
ROUND(1.2345),
ROUND(1.2345, 1),
ROUND(1.2345, 3)
FROM dual;
Output:
ROUND(1.2345) ROUND(1.2345,1) ROUND(1.2345,3)
________________ __________________ __________________
1 1.2 1.235Negative numbers
The Oracle ROUND(number) function allows you to provide a negative number for the second parameter to round the integer part.
SELECT
ROUND(12345, -1),
ROUND(12345, -2)
FROM dual;
Output:
ROUND(12345,-1) ROUND(12345,-2)
__________________ __________________
12350 12300NULL Parameters
If any parameter is NULL, ROUND() will return NULL.
SET NULL 'NULL';
SELECT
ROUND(1, NULL),
ROUND(NULL, 1),
ROUND(NULL, NULL)
FROM dual;
Output:
ROUND(1,NULL) ROUND(NULL,1) ROUND(NULL,NULL)
________________ ________________ ___________________
NULL NULL NULLIn this example, we use the statement SET NULL 'NULL'; to display NULL values as the string 'NULL'.
Conclusion
Oracle ROUND(number) is a built-in function that rounds a given number to a given number of decimal places.