BigDecimal and POW
ZaboApr 7 2013 — edited Apr 7 2013Hello
In the following example, I compute new_amount_d in 2 different ways and I get 2 different values although it should be the same in theory.
Is there a way to get the same value with BigDecimal for instance ?
I'm new to Java and I'm working for financial industry...that's why I'm trying to solve this problem.
Thanks for helping.
public class num004
{
public static void main(String[] args)
{
double amount_d = 1000;
double interest_rate_d = 0.03;
double new_amount_d = amount_d;
for(int i = 0;i<365;i++)
{
new_amount_d = new_amount_d * Math.pow(1+interest_rate_d,(double)1/365);
}
System.out.println("new amount_d :"+new_amount_d);
new_amount_d = amount_d * Math.pow(1+interest_rate_d,(double) 1);
System.out.println("new amount_d :"+new_amount_d);
}
}