DISPLAY is human-readable; PACKED-DECIMAL (COMP-3) is compact exact decimal. Use PACKED-DECIMAL for computation and persistent storage of money; convert to edited DISPLAY for printing.
1234501 PRICE PIC 9(5)V99 PACKED-DECIMAL. 01 QUANTITY PIC 9(5) DISPLAY. 01 TOTAL PIC 9(7)V99 PACKED-DECIMAL. ... COMPUTE TOTAL ROUNDED = PRICE * QUANTITY
Use ROUNDED to control rounding during COMPUTE.
12301 TOTAL-EDIT PIC ZZ,ZZZ,ZZ9.99-. MOVE TOTAL TO TOTAL-EDIT DISPLAY TOTAL-EDIT
Edited pictures provide commas, decimal point, and sign formatting for users.
Mistake | Problem | Fix |
---|---|---|
Using BINARY for money | Inexact decimal values | Use PACKED-DECIMAL |
Missing ROUNDED | Unexpected truncation | Add ROUNDED |
Feature | Usage | Example |
---|---|---|
Implied decimal | V in PICTURE | 9(7)V99 |
Exact decimal | PACKED-DECIMAL | PIC 9(5)V99 COMP-3 |
Edited display | Edited PICTURE | ZZ,ZZZ,ZZ9.99- |
1. Best storage for currency?
2. What does V mean in PICTURE?
3. How to format output for users?