Decimals with V
Part of the First Programs section of Coddy's COBOL Programming journey. Lesson 15 of 19.
V in a picture marks where the decimal point is. PIC 9(3)V99 holds numbers like 123.45. The point is not stored: the field is 5 digits.
01 PRICE PIC 9(3)V99.GnuCOBOL's ACCEPT reads a typed point: 12.50 typed into PRICE stores 12.50. DISPLAY PRICE prints the stored digits with no point: 01250.
To print the point, MOVE the value into a field whose picture has a real one, then display that field:
01 PRICE-OUT PIC 9(3).99.
MOVE PRICE TO PRICE-OUT. *> 012.50A picture with a real point is an edited picture: it is for printing, not arithmetic. Section 2 covers the rest of them.
Challenge
EasyRead PRICE and display it with its decimal point, as Price: 012.50.
Example input, one line per ACCEPT: 12.50.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. PRICES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PRICE PIC 9(3)V99.
01 PRICE-OUT PIC 9(3).99.
PROCEDURE DIVISION.
ACCEPT PRICE.
*> Display the price with its point
STOP RUN.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.