Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

BigDecimal and POW

ZaboApr 7 2013 — edited Apr 7 2013
Hello

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);

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2013
Added on Apr 7 2013
4 comments
271 views