【发布时间】:2010-08-06 21:41:18
【问题描述】:
这里的菜鸟想在 iPhone 上计算复利。
float principal;
float rate;
int compoundPerYear;
int years;
float amount;
公式应为:金额 = 本金*(1+rate/compoundPerYear)^(rate*years)
我得到的答案有点不正确:
amount = principal*pow((1+(rate/compoundPerYear)), (compoundPerYear*years));
我正在以 0.1 的速率对其进行测试,但调试器报告为 .100000001。
我做错了吗?我应该使用双打还是特殊课程(例如 NSNumber)?
感谢您提出任何其他想法!
经过进一步研究,似乎 NSDecimalNumber 类可能正是我所需要的。现在我只需要弄清楚如何使用这个坏男孩。
【问题讨论】:
-
看我的回答stackoverflow.com/questions/14155360/… 可能会有所帮助:)
标签: objective-c math double finance floating-accuracy