d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Mathematical Logics Problem...?
Add Reply New Topic New Poll
Member
Posts: 13,042
Joined: Apr 12 2008
Gold: 0.00
Oct 17 2014 12:54pm
Okay, so on this project, we're to calculate the monthly payment of a loan.

I was given the equation:




Here is what I am using for the values in order to calculate the monthly payment:

Principal(P): 100,000
Rate(I) = 5.5% (.055)
Months(N): 180

I get the output

The monthly payment is $5,500.36
Which according to the example I was given, is incorrect...

Example output: $817.08


I have tried calculating it on a calculator (ti-83) and it resulted in the same number (5500.36)

But, when I go to a monthly interest calculator, it gives me the same number as the example (817.08)

So, I am wonder what I am doing wrong in the following code (assume I input the same variables as above)

Code
double monthlyPayment = 0;
double months = (years * 12);
double top = Math.pow(1+rate, months);
top *= rate;

bottom = Math.pow(1+rate, months);
bottom -= 1;
monthlyPayment = (double)loanAmount*(top/bottom);



I don't understand what I am doing wrong to be perfectly honest...
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Oct 17 2014 01:26pm
Interest rate is annual. divide it by 12 for monthly
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Oct 17 2014 01:33pm
This is due to the equation. (Don't worry me as well as wolfram alpha also calculated 5500 from your equation, not sure if its my order of operations or the equation itself though.

Here is the one I've always used which also gets the correct answer.

M = P * (J/1-(1+J)^-N))

Where M is your monthly payment, J is your monthly interest (annual interested 5.5% divided by 100 divided by 12) and N is the number of months.

100,000 * (0.004583333 / (1 - (1 + 0.004583333) ^ -180) = 817.08



edit:: lab was right it was the divide into its monthly rate part that I forgot while using your equation. Although I find the one I used in highschool much easier to read.

This post was edited by AbDuCt on Oct 17 2014 01:35pm
Member
Posts: 13,042
Joined: Apr 12 2008
Gold: 0.00
Oct 17 2014 01:39pm
Quote (AbDuCt @ Oct 17 2014 02:33pm)
This is due to the equation. (Don't worry me as well as wolfram alpha also calculated 5500 from your equation, not sure if its my order of operations or the equation itself though.

Here is the one I've always used which also gets the correct answer.

M = P * (J/1-(1+J)^-N))

Where M is your monthly payment, J is your monthly interest (annual interested 5.5% divided by 100 divided by 12) and N is the number of months.

100,000 * (0.004583333 / (1 - (1 + 0.004583333) ^ -180) = 817.08

http://i.imgur.com/DHL1Pfc.png

edit:: lab was right it was the divide into its monthly rate part that I forgot while using your equation. Although I find the one I used in highschool much easier to read.


oh, i just need to divide the rate by 12? lol...

:wallbash:

thanks guys LOL

This post was edited by DD_Rocking on Oct 17 2014 01:45pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll