诺布在这里想要计算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类可能正是我所需要的.现在我只需要弄清楚如何使用这个坏男孩.