开发者

Calculate growth rate in iPhone

Ref URL; http://en.wikipedia.org/wiki/Future_value

Earlier similar question; calculate Future value in iPhone

Like we hvae PV (Present value0, FV (Future value), No. of years (N) and growth rate (%)

How can we calculate growth rate (or interest rate) using the other 3 variables in iPhone?

Code for FV below;

-(float) calcFVFromPresentValue: (float) pv interest_rate: (float) interest_rate time: (flo开发者_如何学Goat) time
{
    float fv;

    //pv = 200000.0; // present value
    //i  = 0.012;    // interest rate (1.2%)
    //t  = 5.0;      // time period

    fv = pv * pow (1.0 + interest_rate, time);
    return fv;

}


since r = (FV/PV)^(1/t) - 1, in Objective-C and your variables:

-(float) calcRateFromPresentValue:(float)pv futureValue:(float)fv time:(float)time
{
float rate = 0.0;

rate = pow( (fv/pv), (1/time) ) - 1;
return rate;
}

note: in the future, try doing it on your own first, we're not code monkeys (i add this edit after i monkey your code of course :p)

edit2: left off the minus 1 in the formula.


You're looking for just the equation? Break it down using algebra.

fv = pv * pow (1.0 + interest_rate, time);
fv / pv = pow (1.0 + interest_rate, time); // divide by pv
pow ( fv / pv, 1.0 / time ) = 1.0 + interest_rate; // raise each side by 1/time

// then subtract 1 from each side:
interest_rate = pow ( fv / pv, 1.0 / time ) - 1.0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜