0

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:)

aIDserse
  • 131
  • 8
  • 2
    I see no comma in the above code snippet so where is it? Or do you use the comma instead of a decimal point e.g. 1,1 instead of 1.1? If so then the question is a bit clearer but you need update the question to show the declaration of C, which, I presume, is the variable that you are saying should hold the decimals. I suspect that you have declared it as an integer and not a real. – NicC May 15 '20 at 21:23
  • @NicC, do actually know COBOL? It doesn't have integer and real – JoelFan May 15 '20 at 21:41
  • 3
    Please show us the PIC of C – JoelFan May 15 '20 at 21:41
  • i'm soory, in Italy we use commas... I meant point! – aIDserse May 16 '20 at 00:32
  • @JoelFan Yes, I am familiar with COBOL but obviously Giulio is not. Whole number, number without a fractional part are integers. Real numbers are the number we have in the real world where decimal parts may exist. – NicC May 16 '20 at 09:42
  • 1
    Please read: [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Most of the `DISPLAY` statements are not needed for **minimal** and the absence of the `DATA DIVISION` makes the code not **reproducible**. – Rick Smith May 16 '20 at 16:35

2 Answers2

2

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.
Jim Castro
  • 864
  • 5
  • 10
1

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
RB123
  • 26
  • 1
  • 3
    The `SIN` function argument must be in radians, not degrees. `FUNCTION SIN(A * 3.14159 / 180)` is one option. Also `SIN` may be negative. – Rick Smith May 15 '20 at 23:28
  • looks like it's giving you a floating point value. Maybe you don't realize but a period is used instead of a comma in some countries to separate between the whole and fractional parts of a number. Looks like you can change that too: https://community.microfocus.com/t5/Enterprise-Server-Knowledge-Base/Change-decimal-point-to-a-comma-for-a-numeric-display-field/ta-p/1747319 – JoelFan May 16 '20 at 00:05
  • Sooorryyy I meant the period, I automatically say comma hahahah. Btw it now works on results but I still can't have points on the number I have to insert – aIDserse May 16 '20 at 00:34