小编alr*_*der的帖子

目标C数学公式失败

诺布在这里想要计算iPhone的复利.

float principal;
float rate;
int compoundPerYear;
int years;
float amount;
Run Code Online (Sandbox Code Playgroud)

公式应为:amount = principal*(1 + rate/compoundPerYear)^(rate*years)

我得到的答案略有错误:

amount = principal*pow((1+(rate/compoundPerYear)), (compoundPerYear*years));
Run Code Online (Sandbox Code Playgroud)

我正在以.1的速率测试它,但调试器报告.100000001.

我做错了吗?我应该使用双打还是特殊课程(例如,NSNumber)?

感谢您的任何其他想法!


经过进一步的研究,似乎NSDecimalNumber类可能正是我所需要的.现在我只需要弄清楚如何使用这个坏男孩.

math double finance objective-c floating-accuracy

2
推荐指数
1
解决办法
1336
查看次数

标签 统计

double ×1

finance ×1

floating-accuracy ×1

math ×1

objective-c ×1