aIDserse
aIDserse

Reputation: 131

Commas in cobol?

I'm still working with Cobol:) I have a question, let's take this code:

                          ACCEPT A
                           COMPUTE C= FUNCTION SIN(A)
                           END-COMPUTE
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "IL SENO DI " A " RISULTA..."
                           DISPLAY C " GRADI"

Now, it does Sinus, but the outup is, for example with 37: 00000000000000 GRADI My Scientific Calculator says: 0.6018 As you see COBOL does not show the numbers after comma. Is there a way to show them? Thank you:)

Upvotes: 0

Views: 1885

Answers (2)

Jim Castro
Jim Castro

Reputation: 894

Building on what Rick and RB123 have told you already here's what I see is the answer. The correct way to picture a data item that has a decimal place is with a V showing the position of the implied point and not with a '.' which controls the position the decimal is display at only in an edited output field. The main difference is that you can input or compute on fields with a 'V' and only display or output fields with a '.'

PS. I'm in the US where the decimal point is '.' - some contries use a comma instead. This can be changed by using the DECIMAL-POINT IS COMMA special name.

   IDENTIFICATION DIVISION.
   PROGRAM-ID. Decimals.
   ENVIRONMENT DIVISION.
  * CONFIGURATION SECTION.
  * SPECIAL-NAMES.
  *    DECIMAL-POINT IS COMMA.

   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 A  pic S9(2)V9(5) comp-3.
   01 C  pic S9(2)V9(5) comp-3.

   PROCEDURE DIVISION.
   BEGIN.
       ACCEPT A
       COMPUTE C = FUNCTION SIN(A * 3.14159 / 180)
       DISPLAY "Computing."
       DISPLAY "Computing.."
       DISPLAY "Computing..."
       DISPLAY "Computing...."
       DISPLAY "Computing....."
       DISPLAY "Computing......"
       DISPLAY "IL SENO DI " A " RISULTA..."
       DISPLAY C " GRADI"

       GOBACK.

Upvotes: 2

RB123
RB123

Reputation: 26

My cobol is not gnu, but you can do something like

01 C comp-2.
01 A pic 999.
01 C1 pic 999.999999.

PROCEDURE DIVISION.
BEGIN.
       move 37 to A
       COMPUTE C = FUNCTION SIN(A)
       END-COMPUTE
       move C to C1
       DISPLAY "Computing."
       DISPLAY "Computing.."
       DISPLAY "Computing..."
       DISPLAY "Computing...."
       DISPLAY "Computing....."
       DISPLAY "Computing......"
       DISPLAY "IL SENO DI " A " RISULTA..."
                   DISPLAY C1 " GRADI"

The actual output is

Computing.
Computing..
Computing...
Computing....
Computing.....
Computing......
IL SENO DI 037 RISULTA...
000.643538 GRADI

Upvotes: 1

Related Questions