Numbers

The numeric data types are binary integer, decimal, decimal floating-point, and floating-point.

The numeric data types are categorized as follows:
  • Exact numerics: binary integer and decimal
  • Decimal floating-point
  • Approximate numerics: floating-point

Binary integer includes small integer, large integer, and big integer. Binary numbers are exact representations of integers. Decimal numbers are exact representations of numbers with a fixed precision and scale. Binary and decimal numbers are considered exact numeric types.

Decimal floating-point numbers can have a precision of 16 or 34. Decimal floating-point supports both exact representations of real numbers and approximations of real numbers and so is not considered either an exact numeric type or an approximate numeric type.

Floating-point includes single precision and double precision. Floating-point numbers are approximations of real numbers and are considered approximate numeric types.

All numbers have a sign, a precision, and a scale. For all numbers except decimal floating-point, if a column or expression is zero, the sign is positive. Decimal floating-point numbers include negative and positive zeros. Decimal floating-point has distinct values for a number and the same number with various exponents (for example: 0.0, 0.00, 0.0E5, 1.0, 1.00, 1.0000). The precision is the total number of digits excluding the sign. The scale is the total number of digits to the right of the decimal point. If there is no decimal point, the scale is zero.

Small integer

A small integer is a binary number composed of 2 bytes with a precision of 5 digits. The range of small integers is -32 768 to +32 767.

For small integers, decimal precision and scale are supported by COBOL, RPG, and IBM® i system files. For information concerning the precision and scale of binary integers, see the DDS Reference topic.

Large integer

A large integer is a binary number composed of 4 bytes with a precision of 10 digits. The range of large integers is -2 147 483 648 to +2 147 483 647.

For large integers, decimal precision and scale are supported by COBOL, RPG, and IBM i system files. For information concerning the precision and scale of binary integers, see the DDS Reference topic.

Big integer

A big integer is a binary number composed of 8 bytes with a precision of 19 digits. The range of big integers is -9 223 372 036 854 775 808 to +9 223 372 036 854 775 807.

Decimal

A decimal value is a packed decimal or zoned decimal number with an implicit decimal point. The position of the decimal point is determined by the precision and the scale of the number. The scale, which is the number of digits in the fractional part of the number, cannot be negative or greater than the precision. The maximum precision is 63 digits.

All values of a decimal column have the same precision and scale. The range of a decimal variable or the numbers in a decimal column is -n to +n, where the absolute value of n is the largest number that can be represented with the applicable precision and scale.

The maximum range is negative 1063+1 to 1063 minus 1.

Floating-point

A single-precision floating-point number is a 32-bit approximate representation of a real number. The range of magnitude is approximately 1.17549436 × 10-38 to 3.40282356 × 1038.

A double-precision floating-point number is a IEEE 64-bit approximate representation of a real number. The range of magnitude is approximately 2.2250738585072014 × 10-308 to 1.7976931348623158 × 10308.

Single-precision floating-point is generally accurate to 7 digits of precision. Double-precision floating-point is generally accurate to 15 digits of precision.

Decimal floating-point

A decimal floating-point number is an IEEE 754R number with a decimal point. The position of the decimal point is stored in each decimal floating-point value. The maximum precision is 34 digits. The range of a decimal floating-point number is either 16 or 34 digits of precision, and an exponent range of 10-383 to 10384 or 10-6143 to 106144 respectively.

The minimum exponent, Emin, for DECFLOAT values is -383 for DECFLOAT(16) and -6143 for DECFLOAT(34). The maximum exponent, Emax, for DECFLOAT values is 384 for DECFLOAT(16) and 6144 for DECFLOAT(34).

In addition to the finite numbers, decimal floating-point numbers can also represent the following three special values (see Decimal floating-point constants for more information):
  • Infinity - A value that represents a number whose magnitude is infinitely large.
  • Quiet NaN - A value that represents undefined results which does not cause an invalid number warning.
  • Signaling NaN - A value that represents undefined results which will cause an invalid number warning if used in any numerical operation.1

When a number has one of these special values, its coefficient and exponent are undefined. The sign of an infinity is significant (that is, it is possible to have both positive and negative infinity). The sign of a NaN has no meaning for arithmetic operations.

See Table 2 for more information.

Numeric variables

Small and large binary integer variables can be used in all host languages. Big integer variables can only be used in C, C++, ILE COBOL, and ILE RPG. Floating-point variables can be used in all host languages except RPG/400® and COBOL/400. Decimal variables can be used in all supported host languages. Decimal floating-point variables can only be used in C.

String representations of numeric values

When a decimal, decimal floating-point, or floating-point number is cast to a string (for example, using a CAST specification) the implicit decimal point is replaced by the default decimal separator character in effect when the statement was prepared. When a string is cast to a decimal, decimal floating-point, or floating-point value (for example, using a CAST specification), the default decimal separator character in effect when the statement was prepared is used to interpret the string.

1 The warning is only returned if *YES is specified for the SQL_DECFLOAT_WARNINGS query option.