I just got solved this problem: Conversion from VBA to JS - wrong output (thanks to Terry Lennox!)
But I'd rather would like to do the same calculation with Math.log in stead of the recursive method, my customer suggested.
I am having the following code:
var amount = parseFloat($('#input_loan_amount').val()); //value: 250000
var initial_fee = parseFloat($('#input_initial_fee').val()); //value: 3499
var monthly_fee = parseFloat($('#input_monthly_fee').val()); //value: 99
var monthly = parseFloat($('#input_monthly_interest').val()); //value: 0.41
var rate = parseFloat($('#input_installment').val()); //value:3499
$('#result_albert').html('Calculating ...');
if (amount > 0) {
amount = amount + initial_fee;
if (isNaN(monthly) == true) {
monthly = 0;
}
if (isNaN(rate) == true) {
rate = 0;
}
monthly = monthly / 100;
var monthly2 = Math.round(monthly * 100) / 100;
var months = -(Math.log(1 - (monthly * amount / (rate - monthly_fee)))) / Math.log(1 + monthly);
months = -(Math.log(Math.round((1 - (monthly * amount / (rate - monthly_fee))) * 100) / 100) / Math.log(Math.round((1 + monthly) * 100) / 100));
}
The number before the dot is correct, but the decimals are not correct. I reckon, my formula months= is not quite correct, but my mathematic skills are not high enough ...
