亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在循環中計算多個值

在循環中計算多個值

慕尼黑5688855 2023-11-12 15:11:16
在未來的收入計算器中,我需要顯示5年、10年和15年累積的數據。在這個賬戶中,我計算每月供款的價值,12個月后,我應用年度盈利能力,從而得出一年的最終價值。為了得到第二年的價值,我將 12 個月的總和作為初始值,然后將這 12 個月的價值與盈利能力相加。賬戶如下...contributions = 536,06;profitability = 4.27;fixedYearVal = 536,06 * 12; // 6.432,72profitabilityVal =  (profitability / 100) * fixedYearVal;fixedYearprofitability = fixedYearVal + profitabilityVal;就這樣,我發現第一年就盈利了。第二年的值將為 (secondYear =fixedYearVal +fixedYearprofitability)。第二年的最終金額為percentSecondYear = (profitability / 100) * secondYear;finalSecondYear = percentSecondYear + secondYear;第三年的價值將是thirYear = finalSecondYear + fixedYearVal;percentthirdYear = (profitability / 100) * thirYear;finalThirdyear = percentthirdYear + thirYear;無論如何,正如我所說,我需要它 5 年、10 年和 15 年,除了制作數千行之外,我無法想象任何其他方法,我想過用 Javascript 中的 for 來完成它,但使用這個數據boo我發現自己迷路了。??
查看完整描述

1 回答

?
慕的地6264312

TA貢獻1817條經驗 獲得超6個贊

我把一些東西放在一起。也許這可以幫助您入門。這個想法是 1) 設置一些基值 2) 將其放入您想要計算的 n 年循環中。3)以數組形式返回最終結果,以便您可以逐年查看


// Calculate the next year

const caclNextYear = (lastYear, fixedYearVal, profitability) => {

  const nextYr = lastYear + fixedYearVal;

  const percentSecondYear = (profitability / 100) * nextYr;

  const finalYr = percentSecondYear + nextYr;

  return finalYr;

};


// Calc years by number of years

const estimateByYears = (years) => {

  const contributions = 536.06;

  const profitability = 4.27;

  const fixedYearVal = 536.06 * 12; // 6.432,72

  const profitabilityVal =  (profitability / 100) * fixedYearVal;

  const fixedYearprofitability = fixedYearVal + profitabilityVal;

  const yearByYear = [fixedYearprofitability];


  for (let i = 1; i < years; i++) {

    let lastYr = yearByYear[yearByYear.length - 1];

    yearByYear.push(caclNextYear(lastYr, fixedYearVal, profitability));

  }

  

  return yearByYear;

};


// Call

const yearByYear = estimateByYears(5);

// yearByYear : [6707.397144, 13701.200146048799, 20993.63853628508, 28597.46404578445, 36525.97290453945

console.log('yearByYear', yearByYear);


查看完整回答
反對 回復 2023-11-12
  • 1 回答
  • 0 關注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號