Page 1 of 1

Weired COBOL output.

Posted: Tue Aug 01, 2017 6:24 pm
by Johny Garg
Hi,

Please see this:

Code: Select all

01 WS-COUNTER.
           05 WS-A PIC S9(9) COMP-3.
           05 WS-B PIC 9(9).99.
PROCEDURE DIVISION.
    MOVE 0.4012 TO WS-A.
    MOVE WS-A TO WS-B.
    DISPLAY "A to B: " WS-B.

Code: Select all

output is 0000000000.00
Should not the output be 0000000000.40?

Re: Weired COBOL output.

Posted: Tue Aug 01, 2017 6:59 pm
by Robert Sample
No, the output is what it should be. Moving 0.4012 to WS-A changes the value to zero. Why? Because A has no decimal digits (if not specified, the decimal point is to the RIGHT of the last digit in a PICTURE). Hence the .4012 gets discarded and the value moved to WS-B is 0.

Update: your output does not match the PICTURE clause, too. Your output has 10 digits before the decimal point but WS-B is defined with 9 digits before the decimal point. If you want to post output, post the ACTUAL output, not whatever you interpret the output to be -- many times, your interpretation may not be right and you lose critical information by editing the output (such as adding an extra digits to the output).