View previous topic :: View next topic
|
Author |
Message |
malathy_tv
New User
Joined: 29 May 2007 Posts: 34 Location: chennai
|
|
|
|
hi,
i need to do an computaion, adding two decimal values and storing it in a variable
ex:
declaration are like
A PIC +99999999999.99.
B PIC S9(11)V9(2).
C PIC S9(11)V9(2).
COMPUTE A = B + C
B = 1000.5 and C= 2000.2
the value for A comes as A= 1000.5+2000.2 = +00000003000.70
but i need the vale of A to be A = +00000003000.07
instead of '70' in the decimal part
how can this be done. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
B = 1000.5 and C= 2000.2
the value for A comes as A= 1000.5+2000.2 = +00000003000.70
but i need the vale of A to be A = +00000003000.07
instead of '70' in the decimal part
how can this be done. |
invent a new math theory/architecture |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Why would you want to change the actual result to some ficticious one ? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
On you indows pc, there is a calculator.
Please add your numbers with the decimals as you've shown and notice the calculator arrives at the same answer (the one you want to change).
Quote: |
but i need the vale of A to be A = +00000003000.07 |
Why do you need this value? |
|
Back to top |
|
|
bala_velan27
New User
Joined: 09 Oct 2007 Posts: 1 Location: chennai
|
|
|
|
Hi Malathy,
Here is the solution for your question.
Declare the following codes in working storage section
Code: |
WORKING-STORAGE SECTION.
77 A PIC S9(11)V9(2).
77 B PIC S9(11)V9(2) VALUE 1000.5.
77 C PIC S9(11)V9(2) VALUE 2000.2.
77 D PIC +9(11).9(2).
01 REC1.
02 REC2 PIC 9(12).
02 REC3 PIC 9(01).
02 REC4 PIC 9(01).
02 REC5 PIC 9(01).
01 REC6.
02 REC7 PIC 9(12).
02 REC8 PIC X(01) VALUE '.'.
02 REC9 PIC 9(01).
02 REC10 PIC 9(01). |
In procedure code the following codes:
Code: |
PROCEDURE DIVISION.
COMPUTE A = B + C
MOVE A TO D.
MOVE D TO REC1.
MOVE REC2 TO REC7.
MOVE REC4 TO REC10.
MOVE REC5 TO REC9.
MOVE REC6 TO E.
DISPLAY 'A: ' A.
DISPLAY 'D: ' D.
DISPLAY 'REC1: ' REC1.
DISPLAY 'REC6: ' REC6.
* DISPLAY 'E: ' E.
|
Output :
You will get your desired output
Code: |
A: 000000030007{
D: +00000003000.70
REC1: +00000003000.70
REC6:+00000003000.07 |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
There must be something i am missing
Why all the effort to create an incorrect result?
It is easy to force the answer, but why is an invalid result wanted? In what situation does this become a valid result? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
One thing I have noticed in many ( too many ) posts is that people
just fall in love with the technical, or better.... bit mangling side
losing the proper perspective as far as organizational, business requirement and ... basic arithmetics issues |
|
Back to top |
|
|
mshemanthkumar
New User
Joined: 01 Oct 2008 Posts: 2 Location: Melbourne,Australia
|
|
|
|
hello,
The given Question is wrong with the arithmetic operation using standard COBOL format. But,she might need for some other purpose to need the result.The above code works fine for the question.
with regards,
Hemanth |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello Hemanth,
Keep in mind that just because somthing can be done does not mean that it should be done. When requirements posted differ from standard business practice it is best to understand the requirement before throwing code at it.
Nearly anything can be made to happen with code.
Quote: |
she might need for some other purpose |
We understand this is possible as well, but so far have had no explanation what that purpose might be.
If there is a business reason to do this, having it posted here may help someone with a similar requirement at some later time. If there is no business reason, it probably should not be implemented as discussed. |
|
Back to top |
|
|
|