Код: Выделить всё
function PMT (rate_per_period, number_of_payments, present_value, future_value, type ) {
var q = Math.pow(1 + rate_per_period, number_of_payments);
return (rate_per_period * (future_value + (q * present_value))) / ((-1 + q) * (1 + rate_per_period * (type)));
}
jQuery(document).ready(function ($) {
$(".input").keyup(function () {
var annualIncomeInput = 0;
var depositInput = 0;
var annualIncome = 0;
var deposit = 0;
var mortgage = 0;
var propertyValue = 0;
var monthlyPayments = 0;
annualIncomeInput = $('#annualIncome').val();
depositInput = $('#deposit').val();
annualIncome = parseFloat(annualIncomeInput.replace(/,/g, ''));
deposit = parseFloat(depositInput.replace(/,/g, ''));
if (annualIncomeInput && depositInput) {
if ((deposit / 0.1 - deposit) >= (annualIncome * 4.5)) {
mortgage = annualIncome * 4.5;
propertyValue = mortgage + deposit;
} else {
propertyValue = deposit / 0.1;
mortgage = propertyValue - deposit;
}
monthlyPayments = PMT(0.0307/12, 30*12, mortgage, 0, 0).toFixed(2);
}
propertyValue = parseFloat(propertyValue).toLocaleString();
monthlyPayments = parseFloat(monthlyPayments).toLocaleString();
$('#totalHowMuchCanIBorrow').text('£' + propertyValue);
$('#estimatedCosts').text('£' + monthlyPayments);
})
})
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/701 ... n-i-borrow