Results 1 to 5 of 5
  1. #1
    johnsonjp34 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default 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. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default 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 01:25 AM.

  3. #3
    johnsonjp34 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: calculator language

    Looks reasonable. Thanks.

  4. #4
    johnsonjp34 is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default 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. #5
    rru96 is offline Senior Member
    Join Date
    Sep 2012
    Posts
    106
    Rep Power
    0

    Default 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 05:51 PM.

Similar Threads

  1. Replies: 5
    Last Post: 08-25-2009, 09:41 AM
  2. Is this the right language?
    By rws in forum New To Java
    Replies: 9
    Last Post: 11-15-2008, 03:27 PM
  3. Is JAVA the right language?
    By EDENO in forum New To Java
    Replies: 3
    Last Post: 08-08-2008, 12:29 AM
  4. IDE for new language
    By mitra2008 in forum Eclipse
    Replies: 2
    Last Post: 06-23-2008, 06:43 PM
  5. V language 0.004
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-19-2007, 03:18 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
  •