IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How does the division operand determine decimals


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Absinthia

New User


Joined: 10 Jan 2008
Posts: 36
Location: CHINA

PostPosted: Fri Jan 16, 2009 2:52 pm
Reply with quote

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
View user's profile Send private message
Absinthia

New User


Joined: 10 Jan 2008
Posts: 36
Location: CHINA

PostPosted: Fri Jan 16, 2009 3:10 pm
Reply with quote

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
View user's profile Send private message
km_abdullah

New User


Joined: 03 Nov 2008
Posts: 60

PostPosted: Fri Jan 16, 2009 3:22 pm
Reply with quote

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
View user's profile Send private message
Absinthia

New User


Joined: 10 Jan 2008
Posts: 36
Location: CHINA

PostPosted: Mon Jan 19, 2009 7:13 am
Reply with quote

Thanks a lot, abdullah. It helps
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jan 20, 2009 6:21 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Cobol program to determine the sequen... COBOL Programming 2
No new posts Arithmetic division using Syncsort SYNCSORT 6
No new posts How to determine TLS/SSL version in m... TSO/ISPF 2
No new posts How to determine is PDS member is bei... CLIST & REXX 13
No new posts Is there a way to determine Clist usa... CLIST & REXX 10
Search our Forums:

Back to Top