Browse Source

Math fixes

master
Alexander Yakovlev 5 years ago
parent
commit
ea92be1d92
  1. 23
      custom.js
  2. 12
      style.scss

23
custom.js

@ -13,7 +13,7 @@ function round(num) {
if (num == null) {
return 0;
}
return parseFloat(num.toFixed(2));
return Math.round(num * 100)/100;
}
/*
@ -111,14 +111,14 @@ jQuery(function($){
let year = new Date().getFullYear();
let payments = {};
let due = price - payment_absolute;
let yearly_sum = PMT(0.01*interest, term, -(price - payment_absolute));
let monthly_sum = PMT(0.01*interest/12, term*12, -(price - payment_absolute));
let yearly_sum = round(PMT(0.01*interest, term, -(price - payment_absolute)));
let monthly_sum = round(PMT(0.01*interest/12, term*12, -(price - payment_absolute)));
let month = new Date().getMonth() + 1; // current month
let pay_month = undefined;
let months = 1;
let i = 0;
let total = 0;
while(months < term * 12) {
while(months <= term * 12) {
let year_cur = year + i;
if (payments[year_cur] === undefined) {
payments[year_cur] = {}
@ -126,7 +126,7 @@ jQuery(function($){
payments[year_cur].principal = 0;
payments[year_cur].interest = 0;
payments[year_cur].tax = 0;
while(months < term * 12 && month <= 12) {
while(months <= term * 12 && month <= 12) {
let principal_monthly = round(PPMT(interest*0.01/12, months, term*12, -(price - payment_absolute)));
let interest_monthly = round(monthly_sum - round(PPMT(interest*0.01/12, months, term*12, -(price - payment_absolute))));
let pmi_monthly = round(pmi*0.01*due/12);
@ -138,14 +138,19 @@ jQuery(function($){
total += round(interest_monthly);
total += round(tax / 12);
total += round(insurance / 12);
let log = ""+months+"\t"+principal_monthly+"\t"+interest_monthly+"\t";
if (due / (price - payment_absolute) > 0.8) { // there's still PMI
payments[year_cur].tax += pmi_monthly;
total += round(pmi_monthly);
log += pmi_monthly+"\t";
} else {
log += "0\t";
if (pay_month === undefined) {
pay_month = new Date(year_cur, month, 1);
}
}
log += "\n";
// console.log(log);
month++;
months++;
}
@ -158,9 +163,13 @@ jQuery(function($){
i = 0;
months = 1;
month = 1;
while(months < (term * 12)) {
while(i <= term) {
let year_cur = year + i;
pay = pay - round(payments[year_cur].principal);
if (i == term && pay < 0) {
payments[year_cur].principal += pay;
pay = 0;
}
html += "<tr>";
html += "<td>"+year_cur+"</td>";
html += "<td>"+round(payments[year_cur].principal)+"</td>";
@ -168,7 +177,7 @@ jQuery(function($){
html += "<td>"+round(payments[year_cur].tax)+"</td>";
html += "<td class='hidden-sm-down'>"+round(pay)+"</td>";
html += "</tr>";
while(months < (term * 12) && month <= 12) {
while(months <= (term * 12) && month <= 12) {
months++;
month++;
}

12
style.scss

@ -42,9 +42,6 @@ body {
color: #111;
}
.form-name {
@include make-col(12, $grid-columns);
}
.form-mortgage {
max-width: 450px;
input {
@ -137,14 +134,17 @@ body {
display: inline-block;
transform: rotate(45deg);
}
#nameform,
#estimations {
.form-mortgage-heading {
font-size: $font-size-base * 2;
}
.modal-content {
font-family: $font-family-sans-serif;
background-color: #f5f5f5;
}
}
#estimations {
.form-mortgage-heading {
font-size: $font-size-base * 2;
}
.modal-header {
border: none;
padding-bottom: 0;

Loading…
Cancel
Save