在 JavaScript 中查詢存款金額等於特定金額的日期
問題
我們有一筆金額 amt > 0,我們將其存入賬戶,年利率為 p%,每天除以 360,起始日期為 2021 年 1 月 1 日。我們希望賬戶金額達到 total >= a0。
我們的函式應該接受這三個引數,並返回金額等於目標金額的日期。
示例
以下是程式碼:
const principal = 100;
const amount = 150;
const interest = 2;
const findDate = (principal, amount, interest) => {
const startingDate = new Date('2021-01-01')
const dailyInterestRate = interest / 36000
let startingMoney = principal
let daysPassed = 0
while (startingMoney < amount) {
daysPassed++
startingMoney += startingMoney * dailyInterestRate
};
startingDate.setDate(startingDate.getDate() + daysPassed)
return startingDate.toISOString().split('T')[0]
};
console.log(findDate(principal, amount, interest));輸出
2040-12-26
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP