View previous topic :: View next topic
|
Author |
Message |
sandhyaimmadi
New User
Joined: 18 Aug 2008 Posts: 50 Location: Bangalore
|
|
|
|
Hi,
I have one field which is an amt field which is 6 decimal points.
Requirement is
when I am writing the total amt , I have to sum up all the 6 decimal amt values and truncate it to a 2 decimal value.
Total is a 2 decimal field.
this is a reporting program.
Please suggest.
Current code is
03 COL 3 'TOTAL UNDRAWN'.
03 COL +12 PIC ZZZ,ZZZ,ZZZ,ZZ9.99-
SUM Ws-AMT.
eventhough ws-amt is 6 decimal since they have code decimal 2 in the picture caluse it is not giving proper result. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
sandhyaimmadi wrote: |
Hi,
I have one field which is an amt field which is 6 decimal points.
Requirement is
when I am writing the total amt , I have to sum up all the 6 decimal amt values and truncate it to a 2 decimal value.
Total is a 2 decimal field.
this is a reporting program.
Please suggest.
Current code is
03 COL 3 'TOTAL UNDRAWN'.
03 COL +12 PIC ZZZ,ZZZ,ZZZ,ZZ9.99-
SUM Ws-AMT.
eventhough ws-amt is 6 decimal since they have code decimal 2 in the picture caluse it is not giving proper result. |
Are you using the Cobol Report Writer?
What do you mean by "it is not giving proper result"? Give an example, please, of some lines and what this does "give" for those.
Why do you want to "truncate", and can I have the little bits that fall off the end when you do that please? |
|
Back to top |
|
|
sandhyaimmadi
New User
Joined: 18 Aug 2008 Posts: 50 Location: Bangalore
|
|
|
|
yeah we are using report writer.
Below is the sample
CALC UNDRAWN AMT
602.787944
CALC UNDRAWN AMT
51.509041
TOTAL UNDRAWN 654.28
Actual result should be 654.29 |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Interesting.
Perhaps SUM is "doing something" by default? Have you checked in a manual what it says for how SUM behaves? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
another one who does not bother to read the manual or even think.
to arrive at 654.29, one would have to accumulate to 6 dp,
then move to 2 dp with a round.
since the total is being accumulated in a 2 dp, the truncation is not providing the rounding of the 3rd and 4th dp.
you want the effect of all 6 dp, accumulate at 6 dp. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
What dbz describes is/looks like what is happening, even though your amount has six decimal places.
Look at your other examples, and truncate the detail lines (mentally) to check your total lines. I expect they all then make sense.
So, in how you get from six to truncating at two for the SUM you have to look in the manual and review your code. |
|
Back to top |
|
|
|