# Thread: calculator language

1. Member
Join Date
Sep 2012
Posts
11
Rep Power
0

## calculator language

Greetings all,

I'm attempting to build a compound interest/savings calculator for fun, right? I have defined:

double principal
double annualRate
int periodsPerYear
int years
double savings

I'm trying to figure out the right way to put an exponential in the equation.

The textbook formula would be savings = principal*(1+annualRate/periodsPerYear)^periodsPerYear*year .

How do I write this with the exponent in java/android.

Thanks,

J

2. ## Re: calculator language

I'm thinking it will look something like this:
double savings = Math.pow(principal*(1+annualRate/periodsPerYear), periodsPerYear*year);.
I'm not sure if it works thought. If it doesn't work try swapping the parameters.. Take a look at Math (Java Platform SE 6), double) and you will figure it out :)
Last edited by PhQ; 09-27-2012 at 02:25 AM.

3. Member
Join Date
Sep 2012
Posts
11
Rep Power
0

## Re: calculator language

Looks reasonable. Thanks.

4. Member
Join Date
Sep 2012
Posts
11
Rep Power
0

## Re: calculator language

I tried this double savings = Math.pow(principal*(1+(annualRate/100)/periodsPerYear),periodsPerYear*years); and I keep getting insanely high numbers such as 8.673617379884036E221. Any ideas anyone?

5. Senior Member
Join Date
Sep 2012
Posts
108
Rep Power
0

## Re: calculator language

Your raising it to the exponent of periodsPerYear*years. So if it was basically a \$200,000 principle over 30, you are raising to the power of 360! That should be fairly large should it not. Math.pow()'s second value is for exponent. In this case that would be 30 years * 12 months. If Math.pow(3,3) = 9. Google showed that 2^360 is 2.348543e+108, so imagine the firse value (principle * (1 +..., to the exponent of 360)
Last edited by rru96; 09-28-2012 at 06:51 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•