REAL

The REAL function returns a single-precision floating-point representation of either a number or a string representation of a number.

Numeric to Real:

Read syntax diagram
>>-REAL(numeric-expression)------------------------------------><

String to Real:

Read syntax diagram
>>-REAL(string-expression)-------------------------------------><

The schema is SYSIBM.

Numeric to Real

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 single precision floating-point column or variable. If the numeric value of the argument is not within the range of single precision floating-point, an error occurs.

String to Real

string-expression
An expression that returns a value of a character or graphic string (except a CLOB or DBCLOB) with a length attribute that is not greater than 255 bytes. The string must contain a valid string representation of a number.

The result is the same number that would result from CAST(string-expression AS REAL). Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming an SQL floating-point, integer, or decimal constant.

The result of the function is a single precision floating-point number.

The result can be null; if the argument is null, the result is the null value.

Recommendation: To increase the portability of applications, use the CAST specification. For more information, see CAST specification.
Example: Using sample table DSN8A10.EMP, 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 express the result in single precision floating-point, apply REAL to SALARY so that the division is carried out in floating-point (actually double precision) and then apply REAL to the complete expression so that the results are returned in single precision floating-point.
   SELECT EMPNO, REAL(REAL(SALARY)/COMM)
     FROM DSN8A10.EMP
     WHERE COMM > 0;