
function round_decimals(original_number, decimals) {
  var result1 = original_number * Math.pow(10, decimals)
  var result2 = Math.round(result1)
  var result3 = result2 / Math.pow(10, decimals)
  return (result3)
}


function inflation_factor(FV, IR, NP) {
  var PV = FV / (Math.pow(1 + IR, NP))
  return round_decimals(PV, 2)
}

function future_value(PMT, IR, NP) {
  var FV = PMT * (Math.pow(1 + IR, NP) - 1) / IR
  return round_decimals(FV, 2)
}

// Calculate a Loan Balance
function calculate_balance(PMT, IR, NP) {
  var PV = PMT * (1 - Math.pow(1 + IR, -NP)) / IR
  return round_decimals(PV, 2)
}

function calculate_payment(PV, IR, NP) {
  var PMT = (PV * IR) / (1 - Math.pow(1 + IR, -NP))
  return round_decimals(PMT, 2)
}

function required_deposits(FV, IR, NP) {
  var PMT = FV * IR / (Math.pow(1 + IR, NP) - 1)
  return round_decimals(PMT, 2)
}

function mortgage_amount(PMT, IR, NP) {
  var PR=( PMT * (1 - Math.pow(1 + IR, -NP)) )/IR;
  return round_decimals(PR, 2);
}
// calculates the net present value 
//amt : starting amount
//ir  : interest for each period
//np  : number of periods
function npv(amt,ir,np)
{
   var camt=amt+(amt*(ir/100));
   if(np>0)
   {
	return npv(camt,ir,np-1);
   }
   else
      return round_decimals(camt,2);
}
