w3resource

Oracle ROUND() function

Description

This function is used to return n rounded to integer places to the right of the decimal point.

Using the following rules ROUND() function is implemented:

  • If no integer is defined, then n is rounded to zero places.
  • If the integer specified is negative, then n is rounded off to the left of the decimal point.
  • If n is positive, then :
    ROUND(n, integer) = FLOOR(n * POWER(10, integer) + 0.5) * POWER(10, -integer)
Uses of Oracle ROUND() Function
  • Rounding to nearest integer: Rounds a number to the nearest integer if no decimal places are specified.

  • Decimal place rounding: Rounds a number to a specified number of decimal places.

  • Negative decimal places: Rounds a number to a specified place to the left of the decimal point.

  • Data formatting: Ensures numbers are formatted to a specific precision for reporting and display purposes.

  • Financial calculations: Used in financial calculations where precise rounding to a specific number of decimal places is required.

  • Mathematical operations: Assists in mathematical computations where rounding to a specified precision is necessary.

Syntax:

ROUND(n [, D ])

Parameters:

Name Description
n A number which will be rounded upto D decimal places.
D A number indicating up to how many decimal places n will be rounded.

Pictorial Presentation of ROUND() function

Pictorial Presentation of Oracle ROUND() function

Example:

SELECT ROUND(4.43) FROM dual;

Here is the result.

ROUND(4.43)
-----------
          4

The above statement will round the given number 4.43. No decimal places have been defined, so the default decimal value is 0.

Example: ROUND() function with negative value

SELECT ROUND(-4.53) FROM dual;

Here is the result.

ROUND(-4.53)
------------
          -5

The above statement will round the given number -4.53. No decimal places have been defined, so the default decimal value is 0.

Example: ROUND() function using decimal places

SELECT ROUND(-4.535,2) FROM dual;

Here is the result.

ROUND(-4.535,2)
---------------
          -4.54

The above statement will round the given number -4.535 up to 2 decimal places.

Example: ROUND() function using negative decimal places

SELECT ROUND(34.4158,-1) FROM dual;

Here is the result.

ROUND(34.4158,-1)
-----------------
               30

The above statement will round the given number 34.4158 from the left of decimal place up to 1 place.

Previous: REMAINDER
Next: SIGN



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/oracle/oracle-numeric-functions/oracle-round-function.php