IBM extension
Decimal floating-point literals

A real decimal floating-point constant consists of the following:

Both the integral and fractional parts are made up of decimal digits. You can omit either the integral part or the fractional part, but not both. You can omit either the decimal point or the exponent part, but not both.

Read syntax diagramSkip visual syntax diagramDecimal floating-point literal syntax
 
     .-----------.     .-------.
     V           |     V       |
>>-+---+-------+-+--.----digit-+--+--------------+-+--+-df-+---><
   |   '-digit-'                  '-| exponent |-' |  +-DF-+
   | .-------.                                     |  +-dd-+
   | V       |                                     |  +-DD-+
   +---digit-+--.--+--------------+----------------+  +-dl-+
   |               '-| exponent |-'                |  '-DL-'
   | .-------.                                     |
   | V       |                                     |
   '---digit-+--| exponent |-----------------------'
 
Exponent:
 
                  .-------.
                  V       |
|--+-e-+--+----+----digit-+-------------------------------------|
   '-E-'  +-+--+
          '- --'
 

The suffix df or DF indicates a type of _Decimal32, the suffix dd or DD indicates a type of _Decimal64, and the suffix dl or DL indicates a type of _Decimal128. If a suffix is not specified, the floating-point constant has a type double.

You cannot mix cases in the literal suffix.

The following are examples of decimal floating-point literal declarations:

_Decimal32 a = 22.2df;
_Decimal64 b = 33.3dd;

When using decimal floating-point data, more accurate results will occur if decimal floating-point literals are used. As previously stated, an unsuffixed floating-point constant has type double. Consider this initialization:

_Decimal64 rate = 0.1;

The constant 0.1 has type double, which cannot accurately represent the decimal value 0.1. The variable rate will get a value slightly different from 0.1. The definition should be coded as follows:

_Decimal64 rate = 0.1dd;

When the decimal floating-point literals are converted or when the constant decimal floating-point expressions are resolved, the default rounding mode used will be "round to the nearest, ties to even."

Note:
Decimal floating-point literal suffixes are recognized only when the LANGLVL(*EXTENDED) is specified.
End of IBM extension


[ Top of Page | Previous Page | Next Page | Contents | Index ]