Not every number is a whole integer or a fixed-scale decimal. Scientific measurements, ratios, and some analytic results need floating-point: a significand (coefficient) plus an exponent. Db2 for z/OS offers classic binary floating-point (REAL, FLOAT, DOUBLE) and decimal floating-point (DECFLOAT(16), DECFLOAT(34)) with special values like NaN and Infinity. This page introduces each type and when to prefer DECIMAL instead.
Binary floating-point approximates real numbers using a base-2 representation. That is excellent for wide dynamic range, but many everyday decimal fractions (0.10, 0.01) are repeating patterns in binary—so equality checks and money math can surprise you.
| Type | Storage | Notes |
|---|---|---|
| REAL | 4 bytes | Single-precision binary float; range ~ ±7.2E+75 |
| DOUBLE | 8 bytes | Double-precision binary float; similar huge range, more precision |
| FLOAT(n) | 4 or 8 bytes | n=1–21 → single; n=22–53 → double |
| DECFLOAT(16) | 9 bytes | 16-digit decimal float; exp roughly −383…+384 |
| DECFLOAT(34) | 17 bytes | 34-digit decimal float; enormous exponent range |
REAL is a single-precision (short) floating-point number occupying 32 bits (4 bytes). Approximate range is about −7.2E+75 to 7.2E+75, with tiny magnitudes near ±5.4E−79 at the extremes of normalized positive/negative small values. Use REAL when storage matters and single precision is enough.
DOUBLE (double precision) uses 64 bits (8 bytes). The approximate magnitude range is similar in order to REAL’s huge span, but you get more significant bits—better precision for calculations that still accept binary approximation.
FLOAT(n) lets you request precision with an integer n from 1 to 53:
1234567CREATE TABLE SENSOR_READING ( SENSOR_ID INTEGER NOT NULL, READING_TS TIMESTAMP NOT NULL, TEMP_C REAL, PRESSURE DOUBLE, ALT_METRIC FLOAT(53) );
DECFLOAT is decimal floating-point: coefficients are decimal digits, so values that are exact in base 10 stay exact more naturally than in binary float. Db2 provides two precisions:
12345678CREATE TABLE RISK_FACTOR ( MODEL_ID INTEGER NOT NULL, FACTOR_16 DECFLOAT(16), FACTOR_34 DECFLOAT(34) ); INSERT INTO RISK_FACTOR VALUES (1, DECFLOAT('1.234567890123456E+10'), DECFLOAT('1.23E+100'));
Prefer DECFLOAT when you need decimal semantics with exponential range—analytics, scientific decimal data, or interoperability with decimal float APIs—while still remembering it is not a drop-in replacement for fixed-scale DECIMAL money columns.
Beyond ordinary numbers, DECFLOAT supports special values defined by decimal floating-point arithmetic. The two beginners meet first are NaN and Infinity.
NaN represents an undefined or unrepresentable result (for example, certain invalid operations). It is not the same as SQL NULL. A column can be NOT NULL and still store a NaN if the type is DECFLOAT and your operations produce one. Predicates involving NaN do not behave like ordinary numeric comparisons—consult DECFLOAT comparison and COMPARE_DECFLOAT documentation before writing filters.
Infinity (positive or negative) represents overflow beyond the normal numeric range in floating-point semantics. Like NaN, it is a special value, not NULL. Display, export, and host-language mappings must understand these tokens or you will see confusing conversions.
123456Mental model: NULL -> "no value / unknown" NaN -> "value exists but is not a number" Infinity -> "value exists but is infinite magnitude" 1.25E+5 -> ordinary finite DECFLOAT number
Mixing families in one expression triggers conversions and can inject rounding. Keep columns in one numeric story when possible, and CAST explicitly at boundaries.
COBOL historically maps binary floats to COMP-1 (single) and COMP-2 (double). DECFLOAT support depends on compiler and Db2 version features—confirm your shop’s approved host types before designing DECFLOAT-heavy COBOL. Java and other DDF clients often have dedicated decimal-float or BigDecimal pathways; do not silently shove DECFLOAT into binary double without accepting precision loss.
Floating-point is a number written like “three times ten to the power of something”—a short note that can describe very tiny or very huge amounts without using a thousand digit stickers. Binary float (REAL/DOUBLE) writes that note in computer twos; DECFLOAT writes it with ordinary decimal digits. Sometimes the note says “Infinity” (too huge) or “NaN” (that is not a real number). Those sticky notes are different from an empty box (NULL). For lunch money, use DECIMAL jars with fixed cents—not float notes.
1. REAL in Db2 is:
2. FLOAT(n) with n between 22 and 53 corresponds to:
3. DECFLOAT differs from DOUBLE mainly because:
4. What does NaN mean for DECFLOAT?
5. For bank account balances, the safest default among these is usually: