Calculator js pentru credite bancare

Teoria:
http://www.investopedia.com/articles/03/082703.asp


Practica:

Enter Loan Information:
1) Amount of the loan (any currency):
2) Annual percentage rate of interest:
3) Repayment period in years:



Payment Information:
4) Your monthly payment will be:
5) Your total payment will be:
6) Your total interest payments will be:




Calculul efectiv (javascript):


function calculate() {
// Get the user's input from the form. Assume it is all valid.
// Convert interest from a percentage to a decimal, and convert from
// an annual rate to a monthly rate. Convert payment period in years
// to the number of monthly payments.
var principal = document.loandata.principal.value;
var interest = document.loandata.interest.value / 100 / 12;
var payments = document.loandata.years.value * 12;

// Now compute the monthly payment figure, using esoteric math.
var x = Math.pow(1 + interest, payments);
var monthly = (principal*x*interest)/(x-1);

// Check that the result is a finite number. If so, display the results.
if (!isNaN(monthly) &&
(monthly != Number.POSITIVE_INFINITY) &&
(monthly != Number.NEGATIVE_INFINITY)) {

document.loandata.payment.value = round(monthly);
document.loandata.total.value = round(monthly * payments);
document.loandata.totalinterest.value =
round((monthly * payments) - principal);
}
// Otherwise, the user's input was probably invalid, so don't
// display anything.
else {
document.loandata.payment.value = "";
document.loandata.total.value = "";
document.loandata.totalinterest.value = "";
}
}

// This simple method rounds a number to two decimal places.
function round(x) {
return Math.round(x*100)/100;
}



Link:

http://docstore.mik.ua/orelly/webprog/jscript/ch01_08.htm#jscript4-CHP-1-EX-3


Cartea:

5 comentarii:

  1. interesant blogul tau...am de invatat de pe acest blog

    RăspundețiȘtergere
  2. ms olympia, ma bucur ca posturile mele prezinta interes.

    RăspundețiȘtergere
  3. Atentie: pentru virgula si foloseste "."

    RăspundețiȘtergere
  4. Pentru a intelege si mai bine formula, inca un link util:
    http://en.wikipedia.org/wiki/Mortgage_calculator

    RăspundețiȘtergere
  5. http://www.matheasel.com/calculators/retirement.html

    RăspundețiȘtergere