Omnidex SQL Function: TRUNC

Description

The TRUNC function returns a numeric expression truncated to a specified number of digits to the right of the decimal point. If the specified number of digits is positive and longer than the digits after the decimal point, 0 is added after the fraction digits. If the specified number of digits is negative and larger than or equal to the digits before the decimal point, 0 is returned. When a numeric expression is truncated, the trailing digits are simply dropped off. The return value is not rounded in any way.

This function returns the same datatype as the passed parameter.

Syntax

$ROUND(numeric_expression [, n] )

numeric_expression

Required. Any expression that returns a numeric expression.

n

Optional. An integer n is an integer indicating the number of digits to the right of the decimal. The default is 0.

Example

Example 1: Column

> select latitude, trunc(latitude) from countries with opt=none;

LATITUDE                          TRUNC(COUNTRIES.LATITUDE)
--------------------------------  --------------------------------
                       42.500000                         42.000000
                       24.000000                         24.000000
                       33.000000                         33.000000
                       17.049999                         17.000000
                       18.209999                         18.000000
                       41.000000                         41.000000
                       40.000000                         40.000000

Example 2: Column rounded to a set number of decimal places

Note that floating point values cannot represent ever value, and the values shown below are as close as floating point values can represent.

> select latitude, trunc(latitude, 1) from countries with opt=none;

LATITUDE                          TRUNC(COUNTRIES.LATITUDE,1)
--------------------------------  --------------------------------
                       42.500000                         42.500000
                       24.000000                         24.000000
                       33.000000                         33.000000
                       17.049999                         17.000000
                       18.209999                         18.200001
                       41.000000                         41.000000
                       40.000000                         40.000000

Additional Resources

See also:

 
Back to top
dev/sql/functions/trunc.txt ยท Last modified: 2016/06/28 22:38 (external edit)