View previous topic :: :: View next topic

Author 
Message 
Absinthia
New User
Joined: 10 Jan 2008 Posts: 36 Location: CHINA




Hi, everyone. I met with a problem like below
05 X PIC S9(05)V99.
05 Y PIC S9(05)V99.
05 A PIC 9(4)
05 B PIC 9(4)
Now A is 55, B is 365
COMPUTE X = A/B * 0.0012 * 5470
My question is ,what is the result of A/B, how does cobol determine the decimal points? for example, is the result 0.1506 or0.15068 or 0.15 or something?
I only know if we do it like this
Y = A/B ,the result will be determined by the PIC of Y. but don't the result when it's processed in the middle.
Thanks in advance. 

Back to top 




Absinthia
New User
Joined: 10 Jan 2008 Posts: 36 Location: CHINA




and if the definition of A and B is like this
05 A PIC 9(5)
05 B PIC 9(4)
what will be the result? 

Back to top 


km_abdullah
New User
Joined: 03 Nov 2008 Posts: 60




Hi Absinthia,
COBOL determines the decimal points based on the 'datatype' of resultant variable. The resultant variable stores the intermediate results in the formulae before computing the final result.
Quote: 
COMPUTE X = A/B * 0.0012 * 5470 
In the above case, the result of A/B is '0.15' (since X has 2 dec places) and that is taken into consideration.
Hope this helps! 

Back to top 


Absinthia
New User
Joined: 10 Jan 2008 Posts: 36 Location: CHINA




Thanks a lot, abdullah. It helps 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8117 Location: East Dubuque, Illinois, USA




Quote: 
My question is ,what is the result of A/B, how does cobol determine the decimal points? 
There's a manuals link at the top of the page. Click on the COBOL Programming Guide and pull up Appendix A. This entire appendix discusses how COBOL determines intermediate and final results of arithmetic operations. 

Back to top 


