Skip to content

Instantly share code, notes, and snippets.

@defrindr
Forked from ucay/hitung_kpr.js
Created March 21, 2020 09:14
Show Gist options
  • Save defrindr/ade4d0bf638ade70169ecbc2ecd1cb6c to your computer and use it in GitHub Desktop.
Save defrindr/ade4d0bf638ade70169ecbc2ecd1cb6c to your computer and use it in GitHub Desktop.
[Javascript Function] Hitung KPR
function pmt(rate_per_period, number_of_payments, present_value, future_value, type){
if(rate_per_period != 0.0){
// Interest rate exists
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)));
} else if(number_of_payments != 0.0){
// No interest rate, but number of payments exists
return -(future_value + present_value) / number_of_payments;
}
return 0;
}
function hitung_kpr() {
var harga = $("#kpr_harga").val(),
dp = $("#kpr_dp").val(),
pinjaman = $("#kpr_pinjaman"),
tahun = $("#kpr_tahun").val(),
bunga = $("#kpr_bunga").val(),
result_obj = $("#kpr_result");
if (isNaN(dp)) { alert("isi Persentase Uang muka dengan angka"); return; }
if (isNaN(bunga)) { alert("isi Bunga dengan angka"); return; }
total_dp = harga * dp / 100;
total_pinjaman = harga - total_dp;
pinjaman.empty().html(total_pinjaman).number( true, 0 ,',','.');
total_result = -pmt(bunga/100/12, tahun, total_pinjaman, 0, 0);
result_rupiah = $.number( total_result, 0 ,',','.');
result_obj.html(result_rupiah);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment