Investment Calculator

by BrankoSabo

TypeScript

const yearlyDeposit: number = 4800;
const year0Deposit: number = yearlyDeposit;
const howManyYears: number = 5;
const returnAverage: number = 0.09;
const monthlyTake: number =Math.pow( 0.3 + 1, 12 );
var sum: number = yearlyDeposit;
const currencyCode: string = "EUR"; //"RSD" "USD"

var formatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: currencyCode,

  // These options are needed to round to whole numbers if that's what you want.
  //minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
  //maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
});
console.log(monthlyTake)
for(let i =1;i<= howManyYears; i++){
	sum = sum + sum* returnAverage + yearlyDeposit;
  sum = sum*monthlyTake
  if(i == howManyYears){
  sum -=yearlyDeposit
  }
  console.log(`Year ${i} total: ${formatter.format(sum)}`)
}
console.log(`Total investment: ${formatter.format(yearlyDeposit * howManyYears)}`)
console.log(`Pure investment return: ${formatter.format(sum - yearlyDeposit * howManyYears)}`)
console.log(`Total return: ${formatter.format(sum)}`)