The Simple Mortgage Calculator Implemented in C/C++, Javascript and MySQL


Although there are many available mortgage calculators out there, the principle of a simple mortgage calculator is really simple, which is based on the following math formula.

tex_b0f245bff921eb978537a28184ca56de The Simple Mortgage Calculator Implemented in C/C++, Javascript and MySQL c / c++ javascript mysql tools / utilities

where, the c is the monthly repayment, r is the monthly interests (which is the one-twelveth of the yearly interests). P is the total money borrowed. N is the total number of re-payments (e.g. the number of months).

Simple Mortgage Calculator Implemented in MySQL

For example, I borrowed 170K from the HSBC Bank, the interests rate (yearly) is 2.49%, and I need to repay the principle+interests in 25 years. The amount of repayment each month (suppose it is fixed-rate) can be computed via the following command in MySQL console:

1
2
3
4
5
6
7
mysql> select 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1);
+------------------------------------------------------------------------+
| 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1) |
+------------------------------------------------------------------------+
|                                                       761.792586559163 |
+------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1);
+------------------------------------------------------------------------+
| 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1) |
+------------------------------------------------------------------------+
|                                                       761.792586559163 |
+------------------------------------------------------------------------+
1 row in set (0.00 sec)

Simple Mortgage Calculator Implemented in C/C++

With the pow function from math.h, the payment function is defined as follows:

1
2
3
4
5
6
7
8
9
#include <math.h>
 
// r - monthly interest rate
// p - principle
// n - number of repayments
double payment(r, p, n) {
    var x = pow(1 + r, n);
    return r * p * x / (x - 1);
}
#include <math.h>

// r - monthly interest rate
// p - principle
// n - number of repayments
double payment(r, p, n) {
    var x = pow(1 + r, n);
    return r * p * x / (x - 1);
}

Online Simple Mortgage Calculator Implemented in Javascript

Similarly, the function defined in Javascript is defined as:

1
2
3
4
5
6
7
// r - monthly interest rate
// p - principle
// n - number of repayments
function payment(r, p, n) {
    var x = Math.pow(1 + r, n);
    return r * p * x / (x - 1);
}
// r - monthly interest rate
// p - principle
// n - number of repayments
function payment(r, p, n) {
    var x = Math.pow(1 + r, n);
    return r * p * x / (x - 1);
}

Fill in the values of r, P and N and the the following online mortgage calculator (open in new window) will compute the monthly repayment and interests (not available if you are viewing in Accelerated Mobile Page version):

Principle (money borrowed):

Interests Rate%:

Repayment Years:
Years
Monthly Repayment: .
Total Payments: .
Total Interest: .
mortgage The Simple Mortgage Calculator Implemented in C/C++, Javascript and MySQL c / c++ javascript mysql tools / utilities

mortgage calculator with formula

The alternative version of this mortgage calculator can be found here.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
717 words
Last Post: The RDTSC Performance Timer written in C++
Next Post: How to Protect Your WordPress Login from Brute-Force Attacks - Simple Approach?

The Permanent URL is: The Simple Mortgage Calculator Implemented in C/C++, Javascript and MySQL

Leave a Reply