Considering the taxable amount (rateable), the number of days and the rate, I must calculate the interest applied (with the compound rate formula) but I have a problem with floating-point and rounding applied by DB2 V12 (Z/OS).
(Note: The same statement on DB2 LUW does not give me problems)
The value of the interest that I expect is 17,84€ instead I get 17,86€
I'm using this statement:
SELECT CAST(CAST(RATEABLE AS DECFLOAT)
* ( 1 - ( POWER ( ( 1 + CAST(RATE AS DECFLOAT) / 100 ),
( -1 * CAST(NUMBER_DAYS AS DECFLOAT) / CAST(DIVISOR AS DECFLOAT) )
)
)
) AS DECIMAL(18, 2)
) AS PAYMENT_INTEREST
FROM (
--- I simulate accessing my DB2 table.
SELECT CAST(92247.38 AS DECIMAL(18, 2)) AS RATEABLE,
CAST(0.249000 AS DECIMAL(12, 6)) AS RATE,
INTEGER(28) AS NUMBER_DAYS,
INTEGER(360) AS DIVISOR
FROM SYSIBM.SYSDUMMY1
) AS TEMP
If I defined the "RATE" field as DEC (12,3) the calculation is correct but obviously I would not be able to manage more rates with more decimals.
Now, what am I missing here?
Thanks.