在 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