Skip to content

Instantly share code, notes, and snippets.

@lh0x00
Last active April 13, 2020 04:18
Show Gist options
  • Save lh0x00/22ec40bd5da048f6c966ecaca1c9d8b3 to your computer and use it in GitHub Desktop.
Save lh0x00/22ec40bd5da048f6c966ecaca1c9d8b3 to your computer and use it in GitHub Desktop.
Calculate savings interest
function calculateSavingsInterest(
numberOfMonths = 12,
assetsFirst = 50000000,
amountEachMonth = 15000000,
percentageOfInterest = 5.35,
skipFirstMonth = true,
) {
const startAt = skipFirstMonth ? 1 : 0;
let total = 0;
for (let i = startAt; i <= numberOfMonths; i++) {
total = i === startAt ? assetsFirst : total + amountEachMonth;
let interest = (total * percentageOfInterest) / 100 / 12;
total += interest;
}
return Math.round(total);
}
@lh0x00
Copy link
Author

lh0x00 commented Jun 28, 2019

example:

calculateSavingsInterest(12, 50000000, 15000000, 5.35, true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment