

function ReverseLoanCalculator(e,r,n)
{
/*
RN June 2009
----------------------
math formula - finds the principal from the WEEKLY repayments, rate & term
P=E/((rx(1+r)^n)/(1+r)^n-1)
----------------------
e - EMI
P - Principal (Loan amount)
r - Interest Rate
n - Term (months)
*/

//convert weekly payment amnt to monthly
e=e*52/12;

//convert rate from annual%  to monthly (for monthly compounding)
r=r/100/12;

//P=e/(r*Math.pow((1+r),n)/Math.pow((1+r),n)-1);
var leftside=r*Math.pow((1+r),n);
var rightside=Math.pow((1+r),n)-1;
P=e/(leftside/rightside);
P=Math.round(P);

return P;

}


function CarLoanCalc(p,r,n)
{
/*
RN June 2009
----------------------
math formula - finds the MONTHLY repayments from the principal, rate & term
E=Pxrx(1+r)^n/((1+r)^n-1)
----------------------
E - EMI
p - Principal (Loan amount)
r - Interest Rate
n - Term (months)
*/
//convert rate from annual%  to monthly (for monthly compounding)
r=r/100/12;

//E=p*r*Math.pow((1+r),n)/Math.pow((1+r),n)-1;
var leftside=p*r*Math.pow((1+r),n);
var rightside=Math.pow((1+r),n)-1;
E=leftside/rightside;
E=Math.round(E);

return E;

}

function RoundToPlaces(n,p)
{
  /*
  RN June 2009
  Function to round to the number of places.
  n = the number to round
  p = the number of decimal places
  */
  	var result = Math.round(n*Math.pow(10,p))/Math.pow(10,p);
	return result;
}