Page 1 of 1

DIVISION of COMP-3 variable (intermediate datatype) -Query

PostPosted: Wed Apr 08, 2020 2:35 pm
by hariharan_bk
Hi,
We have a situation where we divide the annual interest rate by 12, to calculate the monthly payment.


01  FIN-AMT       PIC  S9(15)V9(2)    COMP-3 VALUE 125000.00.          
01  NUM-MNTS   PIC  S9(04) COMP VALUE 24.        
01  FREQ1         PIC  S9(04) COMP VALUE 12.      
01  ANNL-RATE  PIC  S9(1)V9(6)  COMP-3 VALUE 0.0599.                
01  WS-TEMP-AMOUNT         PIC S9(08)V9(10)  COMP-3.      
 


I cannot provide the exact formulae, however I can mimic the same to explain the context.
We want to know what will be the intermediate value for this division - ANNL-RATE/12. We are suspecting some kind of truncation which is not providing us an expected result.

0.00499167 is the expectation, however we suspect we get some value around 0.00491....because of which we are losing some $10 amount in the WS-TEMP-AMOUNT

PIC clause for the intermediate value is unaware for us, to determine the issue reason. Please help us here.


COMPUTE WS-TEMP-AMOUNT = (FIN-AMT * NUM-NMTS * (ANNL-RATE/12) ) / FIN-AMT * (1+ANNL-RATE/12)
 

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

PostPosted: Wed Apr 08, 2020 4:25 pm
by sergeyken
For testing purposes: calculate each intermediate result separately, and print them.

It's normal practice for anyone doing the REAL software development, not only blah-blah-blah about it.

Why do you think that someone else will do YOUR job INSTEAD OF YOURSELF?

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

PostPosted: Wed Apr 08, 2020 5:52 pm
by enrico-sorichetti
because of which we are losing some $10


NOPE it depends on the point of view
until Your organisation demonstrates that the computations are carried according to the legal/law standards for financial computations
Your organisation is just stealing from the customer

in most countries the fiscal computations must be done with four decimal digits and the displayed with two
the financial computation IIRc have similar guidelines/rules

thats why the computations are carried on EXPLICITLY step by step to avoid un-auditable intermediate results

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

PostPosted: Wed Apr 08, 2020 6:56 pm
by Robert Sample
Appendix A of the Enterprise COBOL Programming Guide (for whichever version of COBOL your site uses) has explicit details on intermediate results and should have been your FIRST reference.

I also find it interesting that your post gives 8 digits after the decimal point for the result you're looking for, yet the variable you're dividing by 12 only has 6 digits after the decimal point. As long as you are using the calculation you presented, you won't get more than 6 digits after the decimal point in your intermediate results. And no, the intermediate results at the point of the division do NOT depend upon the 10 digits after the decimal point for WS-TEMP-AMOUNT.

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

PostPosted: Wed Apr 22, 2020 11:09 am
by hariharan_bk
Thanks Robert and Enrico. I understand the reason for 6 digit decimal position for the rate division.
Most likely the focus part is on the rate division. I will alter the numerator variable definition and will understand the output decimal digits.

Thanks All.