Objective c 客观数学

Objective c 客观数学,objective-c,ios,math,int,double,Objective C,Ios,Math,Int,Double,我将如何计算复合利率,到目前为止,我有: double principal = [[principalLabel text] doubleValue]; NSLog(@"Principal: %lf",principal); double years = [[yearsLabel text] doubleValue]; NSLog(@"Years: %lf",years); double months = [[monthsLabel text] doubleValue] / 12;

我将如何计算复合利率,到目前为止,我有:

 double principal = [[principalLabel text] doubleValue];
 NSLog(@"Principal: %lf",principal);
 double years = [[yearsLabel text] doubleValue];
 NSLog(@"Years: %lf",years);
 double months = [[monthsLabel text] doubleValue] / 12; 
 NSLog(@"Months: %lf",months);
 double days = ([[daysLabel text] doubleValue] / 365) / 10;
 NSLog(@"Days :%lf",days);
 double rate = ([[rateLabel text] doubleValue] / 100);
 NSLog(@"Rate: %lf",rate);
 double time = years + days + months;
 NSLog(@"Time: %lf",time);

 double total = pow(principal * (1 - rate), time);
 NSLog(@"Total: %lf",total);
 double interest = pow(principal * (1 - rate), time) - principal;
 NSLog(@"Interest: %lf",interest);
 NSString *interestString = [[NSString alloc] initWithFormat:@"%lf",interest];
 NSString *totalString = [[NSString alloc] initWithFormat:@"%lf",total];
 [interestLabel setText:interestString];
 [totalLabel setText:totalString];
如您所见,我有5个UITextFields用于:本金、利率、年、月、日。目前,我不断得到一些答案,虽然我的数学似乎是正确的,但与我想要的实际答案相差甚远。我已经彻底检查了我的代码,没有找到解决方案

My desired result is: E.g.     
M = P * (1+R)^Y              
M = 1000 * (1+0.10)^2       
M = 1210

如果您将NSLog消息的输出也放在您的问题中,那么回答您的问题将更有帮助。目前,一个明显的错误如下:

在这行代码中

double total = pow(principal * (1 - rate), time);
你有一个利率,而你需要

double total = pow(principal * (1 + rate), time);

你在这方面面临的问题是什么?哪里出了问题,还不清楚。代码:
1-rate
,所需公式:
1+R
P*(1+R)^Y
(P*(1-R))^Y有很大不同