View previous topic :: View next topic
|
Author |
Message |
Vinod Y
New User
Joined: 13 May 2008 Posts: 4 Location: India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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
Have a good evening,
d |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
LOL dick that is so true ... expectations and reality can be so far apart at times! |
|
Back to top |
|
|
Vinod Y
New User
Joined: 13 May 2008 Posts: 4 Location: India
|
|
|
|
Thank you Dick and Robert , i got it |
|
Back to top |
|
|
|