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

ROUNDED function not giving desired result


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Thu May 14, 2009 3:25 am
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu May 14, 2009 3:34 am
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

Moderator Emeritus


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

PostPosted: Thu May 14, 2009 4:44 am
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu May 14, 2009 4:56 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts first column truncated in search result IBM Tools 13
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
Search our Forums:

Back to Top