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
 

 

ROUNDED function not giving desired result

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Vinod Y

New User


Joined: 13 May 2008
Posts: 4
Location: India

PostPosted: Thu May 14, 2009 3:04 am    Post subject: ROUNDED function not giving desired result
Reply with quote

Hi,

I have declared two working storage variables as:
Code:
WS-NUM       COMP S9(7)V99.
WS-NUM1     COMP S9(7)V99.


now on
Code:
COMPUTE WS-NUM1 = 100 * (12.34 / 100).
COMPUTE WS-NUM ROUNDED = 100 * (12.34 / 100).


after displaying WS-NUM & WS-NUM1 am getting the below result :
Code:
WS-NUM   = 000001230
WS-NUM1 = 000001200


Now need to know
1) why i am not getting 000001234 in any of the above cases.
2) what changes can help me getting the expected result.
Thank You.
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu May 14, 2009 3:25 am    Post subject:
Reply with quote

Hello,

Try these instead:
Code:

COMPUTE WS-NUM1 = 100.00 * (12.34 / 100.0000).
COMPUTE WS-NUM ROUNDED = 100.00 * (12.34 / 100.0000).
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: Thu May 14, 2009 3:34 am    Post subject:
Reply with quote

1. Why would you expect to get 000001234 in any case? If you haven't done the research in the manuals, don't expect anything -- just accept what occurs.
2. There is a Manuals link at the top of the page. Click on it, find the COBOL Programming Guide, and read Appendix A, which tells you how COBOL calculates intermediate results. Pay particular attention to Appendix 1.1.1 which defines the terms and Appendix 1.1.3.1 which tells you how to calculate the number of decimal places kept for intermediate results of fixed point operations. This should help you.

Also, you can do the multiplication before the division and that will make a difference. So will adding decimal places.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu May 14, 2009 4:44 am    Post subject: Reply to: ROUNDED funtion
Reply with quote

Hi Robert,

In a moment of humor, i almost originally replied (in addition to changing the literals) that one must be careful of what one expects. . .

I suppose we don't both need to post the reference to the manual icon_smile.gif

Have a good evening,

d
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: Thu May 14, 2009 4:56 am    Post subject:
Reply with quote

LOL dick that is so true ... expectations and reality can be so far apart at times!
Back to top
View user's profile Send private message
Vinod Y

New User


Joined: 13 May 2008
Posts: 4
Location: India

PostPosted: Thu May 14, 2009 12:35 pm    Post subject:
Reply with quote

Thank you Dick and Robert , i got it icon_smile.gif
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 What is the Extract Function in JCL dharmaraok JCL & VSAM 3 Wed Jun 14, 2017 9:12 am
No new posts DB2 Program abending without giving a... rahulgarg14 DB2 7 Mon May 29, 2017 8:10 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts scheduling between OPC and TWS give u... nsbl IBM Tools 4 Sun Mar 12, 2017 5:35 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am


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