DB2 Scalar functions - DOUBLE_PRECISION or DOUBLE


Volta a página anterior

Volta ao Menu das scalar functions

Volta ao Menu Principal


Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

DOUBLE_PRECISION or DOUBLE

The DOUBLE_PRECISION and DOUBLE functions return a double-precision floating-point representation of either a number or a string representation of a number.

Numeric to DOUBLE

DOUBLE_PRECISIONDOUBLE (numeric-expression)

String to DOUBLE

DOUBLE_PRECISIONDOUBLE (string-expression)

The schema is SYSIBM.

Numeric to DOUBLE
numeric-expression
An expression that returns a value of any built-in numeric data type.

The result is the same number that would occur if the argument were assigned to a double-precision floating-point column or variable.

String to DOUBLE
string-expression
An expression that returns a string, including FOR BIT DATA, that represents a number.
The data type of this expression cannot be CLOB, BLOB, or DBCLOB (SQLSTATE 42884).

The result is the same number that would result from the statement CAST(string-expression AS DOUBLE PRECISION).
Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming a valid numeric constant (SQLSTATE 22018).
If the numeric value of the argument is not within the range of double-precision floating-point, an error is returned (SQLSTATE 22003).

The result of the function is a double-precision floating-point number.
If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Notes

  • The CAST specification should be used to increase the portability of applications.
  • FLOAT is a synonym for DOUBLE_PRECISION and DOUBLE.
  • The SYSFUN version of DOUBLE (string_expression) continues to be available.

Example

Using the EMPLOYEE table, find the ratio of salary to commission for employees whose commission is not zero.
The columns involved (SALARY and COMM) have DECIMAL data types.
To eliminate the possibility of out-of-range results, DOUBLE is applied to SALARY so that the division is carried out in floating point:

   SELECT EMPNO
   ,      DOUBLE(SALARY)/COMM
   FROM   EMPLOYEE
   WHERE  COMM > 0


© Copyright IBM Corp.