Reputation: 253
I’m just starting with COBOL, and I’m testing storing and displaying values on the screen. When the user enters the value 10.5 in the terminal, the program stores it as 10.0. I’m using the GnuCOBOL compiler. Why doesn’t it save the value 10.5? Thank you. The code is this:
IDENTIFICATION DIVISION.
PROGRAM-ID. CALC1000.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
77 INTEREST-RATE PIC 9(2)V9.
PROCEDURE DIVISION.
DISPLAY "INTEREST-RATE? "
ACCEPT INTEREST-RATE.
DISPLAY "INTEREST-RATE : " INTEREST-RATE.
STOP RUN.
Upvotes: 0
Views: 66
Reputation: 76
There is a complete thread in this link (someone has written a "NUMCHECK.cbl" routine to make a complex validation number):
From this thread there is a very simple approach in the last comment, that I tested and it works fine:
WORKING STORAGE SECTION.
01 amount pic x(9).
01 edit-amount pic -99999.99.
PROCEDURE DIVISION.
DISPLAY 'AMOUNT? --> '
accept amount.
move amount to edit-amount.
DISPLAY 'edit-amount = ' edit-amount.
I hope it helps you.
Upvotes: 4