View previous topic :: View next topic
|
Author |
Message |
Balu5491
New User
Joined: 01 Aug 2016 Posts: 14 Location: India
|
|
|
|
INPUT WILL BE '-1234567891' WITH PIC X(11).
EXPECTED OUTPUT IS WITH PIC S9(8)V9(2) AS '-12345678.91'
SIMILARLY WHEN INPUT IS '01234567891' WITH PIC X(11). EXPECTED OUTPUT IS WITH PIC S9(8)V9(2) AS '12345678.91'
I tried below code,
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AMOUNT-R-X.
05 AMOUNT-R PIC 9(11).
01 AMOUNT-R-AM PIC S9(8)V9(2).
PROCEDURE DIVISION.
MOVE '-1234567890' to AMOUNT-R
DISPLAY 'AMOUNT-R :' AMOUNT-R
MOVE AMOUNT-R-X TO AMOUNT-R-AM
DISPLAY 'AMOUNT-R-AM :' AMOUNT-R-AM
STOP RUN. |
and got the output
AMOUNT-R :-1234567890
AMOUNT-R-AM :+-1234567.89
still i think i am missing somewhere.. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You CANNOT achieve what you want the way you stated it. The V in a COBOL PICTURE clause is an implied decimal point -- it does not exist at all, ever. Depending upon exactly what you want, you could use a numeric edited PICTURE clause such as PIC 9(08).9(02) or you could separate the integer and decimal parts of the source value and move them separately.
And you made no provision for the sign in your PICTURE -- so I think you will probably be surprised at the results you get, whichever route you go. |
|
Back to top |
|
|
Balu5491
New User
Joined: 01 Aug 2016 Posts: 14 Location: India
|
|
|
|
Hi Robert,
Thanks,
I tried the first option PIC 9(08).9(02) but still i could not achieve what i wanted.
INPUT '-1234567891' WITH PIC X(11).
EXPECTED OUTPUT IS WITH PIC S9(8)V9(2) AS '-12345678.91' |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Why do you expect to see a decimal point when there isn't one? The 'V' is an implied i.e. imaginary decimal point position - not a real one. Your input is integer, until you divide it (by 100) you will not get a decimal. |
|
Back to top |
|
|
Balu5491
New User
Joined: 01 Aug 2016 Posts: 14 Location: India
|
|
|
|
Hi Nic, Robert,
Thanks...
I need to display it in sysout for observation purpose, so visually we need decimal point.
I have done the code as below and that satisfies my request:
Quote: |
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AMOUNT-R PIC X(11).
01 AMOUNT-R9 PIC 9(10).
01 FINALVAL PIC S9(11)V9(2).
01 SIGNCHECK PIC X(1).
PROCEDURE DIVISION.
MOVE '-1234567891' to AMOUNT-R
DISPLAY 'INPUT VALUE :' AMOUNT-R
MOVE AMOUNT-R(1:1) TO SIGNCHECK
MOVE AMOUNT-R TO AMOUNT-R9
IF SIGNCHECK = '-'
COMPUTE FINALVAL= -1 * (AMOUNT-R9 / 100);
DISPLAY 'TOTAL AMOUNT :' FINALVAL
ELSE
COMPUTE FINALVAL= AMOUNT-R9/100;
DISPLAY 'TOTAL AMOUNT :' FINALVAL
END-IF
STOP RUN. |
|
|
Back to top |
|
|
|