函數(shù)
/**
計(jì)算本息和
@param principal 本金
@param time 時(shí)間(天)
@param sevenyearInterestRate 七日年利率
*/
static void CalculateRevenue(double principal,int time,double sevenyearInterestRate){
double principalAndInterest = principal;
double interest = sevenyearInterestRate/365;// 日利率
for (int i = 0; i<time; i++) {
principalAndInterest += principalAndInterest*interest;
}
NSLog(@"本金%f \n 經(jīng)過(guò)%d天\n 本息和%f\n 盈利%f",principal,time,principalAndInterest,(principalAndInterest-principal));
}
使用
// 計(jì)算余額寶本息和
double principal = 50000.00f;//本金
int time = 485;//時(shí)間
double sevenyearInterestRate = 0.03886f;// 七日年利率
CalculateRevenue(principal,time,sevenyearInterestRate);
log如下
本金50000.000000
經(jīng)過(guò)485天
本息和52649.468744
盈利2649.468744
復(fù)雜一點(diǎn),引入一些定制化的需求(比如每月會(huì)取款一定金額)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。