Start of change

DECFLOAT_FORMAT

The DECFLOAT_FORMAT function returns a DECFLOAT(34) value that is based on the interpretation of the input string using the specified format.

Read syntax diagramSkip visual syntax diagram DECFLOAT_FORMAT ( string-expression ,format-string )
string-expression
An expression that returns a built-in character string or graphic string data type. If the value is a graphic data type, it is implicitly cast to VARCHAR before evaluating the function. Leading and trailing blanks are removed from the string. If format-string is not specified, the resulting substring must conform to the rules for forming an SQL integer, decimal, floating-point, or decimal floating-point constant and not be greater than 63 characters after stripping leading and trailing blanks. Otherwise, the resulting substring must contain the components of a number that correspond to the format specified by format-string.
format-string
An expression that returns a built-in character string or graphic string data type. If the value is a graphic data type, it is implicitly cast to VARCHAR before evaluating the function. format-string contains a template of how string-expression is to be interpreted for conversion to a DECFLOAT value. format-string must contain a valid combination of the listed format elements according to the following rules:
  • At least one '0' or '9' format element must be specified.
  • A sign format element ('S', 'MI', 'PR') can be specified only one time.
  • A decimal point format element can be specified only one time.
  • Alphabetic format elements must be specified in upper case.
  • A prefix format element can only be specified at the beginning of the format string, before any format elements that are not prefix format elements. When multiple prefix format elements are specified they can be specified in any order.
  • A suffix format element can only be specified at the end of the format string, after any format elements that are not suffix format elements. When multiple suffix format elements are specified they can be specified in any order.
  • A comma or G format element can be the first format element that is not a prefix format element. There can be any number of comma or G format elements.
  • Blanks must not be specified between format elements. Leading and trailing blanks can be specified but are ignored.
Table 1. Format elements for the DECFLOAT_FORMAT function
Format element Description
0 or 9 Represents a digit that can be included at the specified location. Both format elements have the same meaning.
S Prefix: If string-expression represents a negative number, a leading minus sign (−) is expected at the specified location. If string-expression represents a positive number, a leading plus sign (+) or leading blank can be included at the specified location.
$ Prefix: A leading dollar sign ($) is expected at the specified location.
MI Suffix: If string-expression represents a negative number, a trailing minus sign (−) is expected at the specified location. If string-expression represents a positive number, a trailing blank can be included at the specified location.
PR Suffix: If string-expression represents a negative number, a leading less than character (<) and a trailing greater than character (>) are expected. If string-expression represents a positive number, a leading blank and a trailing blank can be included.
, Specifies the expected location of a comma. This comma is used as a group separator.
. Specifies the expected location of the period. This period is used as a decimal point.
L Prefix or Suffix: Specifies that the local currency symbol is expected at the specified location. The currency symbol is retrieved from message CPX8416 in message file QCPFMSG in library *LIBL.
D Specifies that the local decimal point character is expected at the specified location. The decimal character is retrieved from message CPX8416 in message file QCPFMSG in library *LIBL.
G Specifies that the local group separator character is expected at the specified location. If the local decimal character as retrieved from message CPX8416 in message file QCPFMSG in library *LIBL is a period, the group separator will be a comma. If the local decimal character is a comma, the group separator will be a period.

The result is a DECFLOAT(34). If any argument of the DECFLOAT_FORMAT function can be null, the result can be null; if any argument is null, the result is the null value.

Note

Syntax alternatives: TO_NUMBER is a synonym for DECFLOAT_FORMAT.

Examples

Example Result
DECFLOAT_FORMAT( '123.45' ) 123.45
DECFLOAT_FORMAT( '-123456.78' ) -123456.78
DECFLOAT_FORMAT( '+123456.78' ) 123456.78
DECFLOAT_FORMAT( '1.23E4' ) 12300
DECFLOAT_FORMAT( '123.4', '9999.99' ) 123.40
DECFLOAT_FORMAT( '001,234', '000,000' ) 1234
DECFLOAT_FORMAT( '1234 ', '9999MI' ) 1234
DECFLOAT_FORMAT( '1234-', '9999MI' ) -1234
DECFLOAT_FORMAT( '+1234', 'S9999' ) 1234
DECFLOAT_FORMAT( '-1234', 'S9999' ) -1234
DECFLOAT_FORMAT( ' 1234 ', '9999PR' ) 1234
DECFLOAT_FORMAT( '<1234>', '9999PR' ) -1234
DECFLOAT_FORMAT( '$123,456.78', '$999,999.99' ) 123456.78
End of change