Packed decimal
A compact way of storing numbers, two digits per byte, used heavily for amounts in business records.
Also written COMP-3, comp-3, decimal
Packed decimal, declared in COBOL as COMP-3, stores a number as digits rather than as a binary value, packing two digits into each byte with the sign in the last half-byte.
It exists because business data is decimal. Money has exactly two decimal places and must not drift, and packed decimal arithmetic gives exact decimal results with no conversion and no floating-point surprises. Mainframe hardware performs arithmetic on this format directly, so it is fast as well as accurate.
It is also compact. A nine-digit signed amount takes five bytes instead of nine, which mattered enormously when storage was expensive and still matters when you are reading a hundred million records.
The catch is that packed fields are not readable text. Displaying one without converting it produces nonsense on screen, and this surprises everyone the first time they browse a file containing amounts.
COBOL offers other computational formats too, binary and floating point among them, but for currency and quantities in business records, packed decimal is the one you will meet constantly.
Related terms
- PICTURE clauseThe COBOL declaration that says what kind of data a field holds and how long it is, written as PIC.
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.
- EBCDICThe character encoding mainframes use, where letters and numbers are stored as different byte values than on a laptop.
- CopybookA shared block of COBOL declarations kept in a library and included into programs, so a record layout is defined once.