w3resource

Oracle TRUNC() function

Description

This function is used to truncate a number (n1) to a specified number of decimal places (n2).
When n2 is omitted, then n1 is truncated to 0 places.
n2 can be negative to truncate (make zero) n2 digits left of the decimal point.

Uses of Oracle TRUNC() Function
  • Truncate to specific decimal places: Adjust a number to a desired number of decimal places.

  • Remove fractional part: Simplify numbers by removing their fractional parts.

  • Format numerical data: Prepare data for reporting by truncating values to a standard format.

  • Financial calculations: Use in financial applications to truncate values to the nearest whole number or specified decimal places.

  • Data processing: Preprocess numerical data for further analysis or computation.

Syntax:

TRUNC(n1 [, n2 ])

Arguments:

Name Description
n1 A number which is to be truncated up to n2 decimal places.
n2 A number indicating up to how many decimal places, n1 is to be truncated.

Pictorial Presentation of TRUNC() function

Pictorial Presentation of Oracle TRUNC() function

Example:

SELECT TRUNC(2.465,1) FROM dual;

Here is the result.

TRUNC(2.465,1)
--------------
           2.4

The above statement will return a value truncating 2.465 up to 1 decimal place.

Example: TRUNC() function with negative decimal places

SELECT TRUNC(142.465,-2) FROM dual;

Here is the result.

TRUNC(142.465,-2)
-----------------
              100

The above statement will return a value truncating 142.465 up to -2 decimal places.

Previous: TANH
Next: WIDTH_BUCKET



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://w3resource.com/oracle/oracle-numeric-functions/oracle-trunc-function.php