tags around your samples when posting here... The wrong result is cause by your double values. native decimal numbers are not precise because of two resons: <ol><li>there is s limmited number of bits/bytes to represent the value. <li>binary representation used by the Computer differs from human readable decimal format in that way that some decimal fractions form entless binary fractions, wich connot be represented due to leck of bits/bytes </ol> Use only <tt>BigDecimal</tt> objects and their methods for calulation. bye TPD
OK, according to what I red, I understood that BigDecimal is the solution.
But, How to compute power( BigDecimal, 1/365) ?
In the API, I saw only power(BigDecimal,int).
The second line of code uses an exponent of '1' which means it doesn't compute a 'power' at all. Anything raised to the power of '1' is just the same value. The first example uses '1/365' as the exponent and that is way different than the '1' used in the second example.
new_amount_d = new_amount_d * Math.pow(1+interest_rate_d,(double)1/365); . . . new_amount_d = amount_d * Math.pow(1+interest_rate_d,(double) 1);