Oracle / PLSQL: TRUNC Function (with numbers)

This article is written about how to use the Oracle/PLSQL TRUNC characteristic (as it applies to numeric values) with syntax and examples.

Description

The Oracle/PLSQL TRUNC characteristic returns a range truncated to a sure range of decimal places.

Syntax (with numbers)

The syntax for the TRUNC characteristic in Oracle/PLSQL is:

TRUNC( number [, decimal_places] )

Parameters or Arguments

number The variety to truncate. decimal_places Optional. The quantity of decimal places to truncate to. This price must be an integer. If this parameter is omitted, the TRUNC feature will truncate the wide variety to 0 decimal places.

Returns

The TRUNC characteristic (as it applies to numbers) returns a numeric value.

Applies To

The TRUNC function can be used in the following versions of Oracle/PLSQL:

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Example (with numbers)

Let’s seem to be at some Oracle TRUNC feature examples and explore how to use the TRUNC function in Oracle/PLSQL.

For example:

TRUNC(125.815)
Result: 125

TRUNC(125.815, 0)
Result: 125

TRUNC(125.815, 1)
Result: 125.8

TRUNC(125.815, 2)
Result: 125.81

TRUNC(125.815, 3)
Result: 125.815

TRUNC(-125.815, 2)
Result: -125.81

TRUNC(125.815, -1)
Result: 120

TRUNC(125.815, -2)
Result: 100

TRUNC(125.815, -3)
Result: 0