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.

>>-DECFLOAT_FORMAT--(--string-expression--+------------------+--)-><
                                          '-,--format-string-'      

The schema is SYSIBM.

string-expression
An expression that returns a value that is a CHAR and VARCHAR data type. If a supplied argument is a GRAPHIC or VARGRAPHIC data type, it is first converted 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 42 bytes. Otherwise, the resulting substring must contain the components of a number that corresponds to the format specified by format-string.
format-string
An expression that returns a value that is a built-in character string data type. If a supplied argument is a graphic string (except DBCLOB), it is first converted to a character string before the function is evaluated. The actual length must not be greater than 254 bytes.

The value is a template for 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.
  • A comma format element can be the first format element that is not a prefix format element. There can be any number of comma 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 Represents a digit.

A digit is expected if the '0' format element is to the left of the decimal point. Leading zeros must be specified if there are fewer digits to the left of the decimal point in the string-expression than in the format-string. A digit can be included if the '0' format element is to the right of the decimal point.

9 Represents a digit that can be included at the specified location.
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.
Represents a group separator. A group separator is expected at the specified location if there is a character to the left of it that is not a prefix character.
. A period represents a decimal point that is expected at the specified location.

If format-string is not specified, string-expression must conform to the rules for forming an SQL integer, decimal, floating-point, or decimal floating-point constant and have a length not greater than 42 bytes.

The result is a DECFLOAT(34).

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

Syntax alternatives: TO_NUMBER is a synonym for DECFLOAT_FORMAT.
Table 2. Examples of DECFLOAT_FORMAT
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