RSS

Excel PMT function for Objective-C

01 Dec

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.

Download Sample Project

 

Advertisement
 

About craigmellon

Software development manager for eTech Ltd. I started out developing with Visual Basic 3 and have used all versions of Visual Studio and now. Have recently developed a work management system using Silverlight, and an asset management system using WPF. Currently developing mobile survey solutions using .Net Compact Framework and currently learning IOS development to move our survey solution onto the iPhone/iPad.
Leave a comment

Posted by on December 1, 2011 in Development, iPhone, Objective-C

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.