noob這裏想要計算iPhone上的複利。客觀C數學公式失敗
float principal;
float rate;
int compoundPerYear;
int years;
float amount;
公式應該是:金額=本金*(1種+速度/ compoundPerYear)^(費率*年)
我得到稍微不正確的答案有:
amount = principal*pow((1+(rate/compoundPerYear)), (compoundPerYear*years));
我測試它的速率爲.1,但調試器報告.100000001。
我做錯了嗎?我應該使用雙打還是特殊類別(例如NSNumber)?
感謝您的任何其他想法!
經過進一步研究似乎NSDecimalNumber類可能正是我需要的。現在我只需要弄清楚如何使用這個壞男孩。
看到我的答案http://stackoverflow.com/questions/14155360/convert-to-float-and-calculate/14155699#14155699可能會有所幫助:) – TheTiger 2013-01-05 08:04:22