Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How does the division operand determine decimals

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How does the division operand determine decimals
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    Post subject:
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    Post subject:
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    Post subject:
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: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Tue Jan 20, 2009 6:21 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Determine Region with max bandwidth f... seahawk789 COBOL Programming 3 Mon Feb 27, 2017 8:26 pm
No new posts Identification Division anandgbe COBOL Programming 2 Sat May 28, 2016 11:51 am
No new posts How to determine where is error in ab... jackzhang75 PL/I & Assembler 13 Fri Apr 15, 2016 2:01 am
No new posts To determine the range on a Alphanume... Prasanth Kumar COBOL Programming 3 Mon Feb 15, 2016 9:35 am
No new posts Starts DEBUGGING by Procedure Divisio... jackare Testing & Performance analysis 4 Sun Jan 10, 2016 10:37 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us