DECIMAL Function

Purpose

Converts an arithmetic or string value to a DECIMAL number.

Syntax

DECIMAL(x)

or

DECIMAL(x,p)

or

DECIMAL(x,p,q)

Abbreviation(s): DEC for DECIMAL.

Parameters

x is an arithmetic or string value, and p and q are integer constants representing precision and scale factor, respectively.

Description

The DECIMAL function converts an arithmetic or string value x to a DECIMAL number of an optionally specified precision p and scale factor q. p indicates the precision of the result. q indicates the scale of the result. If p alone is given, q is assumed to be zero.

If x is a floating-point value, the result is a float decimal value, and q must be omitted; otherwise, the result is a fixed decimal value, and if q is omitted, the result is an integer of precision p.

If p is omitted, the result has a precision determined by the rules for type conversion given in the chapter Data Type Conversions.

Examples

DECIMAL('3.14')  /* returns 3 */