When doing real estate development, we often need to use calculators. This is our algorithm for equal principal and interest and equal principal. Let’s look at an example of calculating equal principal and interest and equal principal using PHP. The details are as follows .
I recently encountered the problem of equal amounts of principal and equal amounts of principal and interest while working on a project. If you don’t understand these two methods, click here to read. Otherwise, just skip reading the code. This code is also Can be used for the development of mortgage calculator projects.
Equated principal and interest calculation formula: [Loan principal × monthly interest rate × (1 + monthly interest rate) ^ number of repayment months] ÷ [ (1 + monthly interest rate) ^ number of repayment months - 1 ]
Equated principal calculation formula: Monthly repayment amount = (Loan principal ÷ Number of repayment months) (Principal - Accumulated amount of principal repaid) × Monthly interest rate
The ^ symbol represents exponentiation.
Examples
Assume that the principal is 10,000 yuan, the bank loan is for 10 years, and the base interest rate is 6.65%. Compare the differences between the two loan methods:
Equal principal and interest repayment method
Monthly interest rate=annual interest rate÷12=0.0665÷12=0.005541667
Monthly repayment of principal and interest = [10000×0.005541667×(1+0.005541667)^120]÷〔(1+0.005541667)^120-1〕=114.3127 yuan
Total repayment is 13717.52 yuan
Total interest 37.1752 million yuan
Equal principal repayment method:
Monthly repayment amount = (loan principal ÷ number of repayment months) (principal - cumulative amount of principal repaid) × monthly interest rate
= (10000 ÷120) (10000- cumulative amount of principal that has been returned) × 0.005541667
The first month’s repayment is RMB 138.75, with monthly repayment decreasing by RMB 0.462
Total repayment is 13352.71 yuan
Equal principal and interest
代码如下 | 复制代码 |
function debx() |
The code is as follows | Copy code | ||||
function debx() { $dkm = 240; //Number of loan months, 20 years is 240 months $dkTotal = 10000; //Total loan amount
"; $dkTotal = $dkTotal - $em; $lxTotal = $lxTotal $lx; } echo "Total interest:" . $lxTotal; } |
The code is as follows | Copy code |
function debj()
{
$dkm = 240; //Number of loan months, 20 years is 240 months
$dkTotal = 10000; //Total loan amount
$dknl = 0.0515; //Loan annual interest rate
$em = $dkTotal / $dkm; //Monthly repayment of principal
$lxTotal = 0; //Total interest
for ($i = 0; $i < $dkm; $i ) {
$lx = $dkTotal * $dknl / 12; //Monthly repayment interest
echo "No." . ($i 1) . "Period", "Principal:", $em, "Interest:" . $lx, "Total amount:" . ($em $lx), " |