I’ve been working on an iPad/iPhone app that needed to calculate the monthly payments of a loan based on a specified APR. Excel has a PMT function which can be used for this. I had a good search around google but couldn’t find an Objective-C function.
I found some java-script code which I have re-wrote into Object-C, the function is as follows:
-(float)calculatPMTWithRateForPeriod:(double)rateForPeriod numberOfPayments:(NSInteger)numberOfPayments loanAmount:(double)loanAmount futureValue:(double)futureValue type:(NSInteger)type
{double q;
q = pow(1 + rateForPeriod, numberOfPayments);
return (rateForPeriod * (futureValue + (q * loanAmount))) / ((-1 + q) * (1 + rateForPeriod * (type)));
}
I’ve also attached a simple demo project showing the calculator working on the iPhone.
