gpt4 book ai didi

objective-c - Objective C 数学

转载 作者:行者123 更新时间:2023-11-29 11:13:12 24 4
gpt4 key购买 nike

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

 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 个 UITextField:本金、利率、年、月、日。目前,我不断得到一些答案,但与我所寻求的实际答案相去甚远,尽管我的数学看起来是正确的,但我已经彻底检查了我的代码,但没有找到解决方案。

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);

你有 1 - 费率,而你需要有

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

关于objective-c - Objective C 数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10570591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com