search
Homephp教程PHP源码PHP equal principal and interest, equal principal calculation example

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

181.4511278796992481203007518797 1.12502104984600E 271 1.005541667^120-1 0.9409241291

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

Interest 3352.71 yuan

Equal principal and interest

 代码如下 复制代码

function debx()
{
$dkm     = 240; //贷款月数,20年就是240个月
$dkTotal = 10000; //贷款总额
$dknl    = 0.0515;  //贷款年利率
$emTotal = $dkTotal * $dknl / 12 * pow(1 $dknl / 12, $dkm) / (pow(1 $dknl / 12, $dkm) - 1); //每月还款金额
$lxTotal = 0; //总利息
for ($i = 0; $i $lx      = $dkTotal * $dknl / 12;   //每月还款利息
$em      = $emTotal - $lx;  //每月还款本金
echo "第" . ($i 1) . "期", " 本金:", $em, " 利息:" . $lx, " 总额:" . $emTotal, "
";
$dkTotal = $dkTotal - $em;
$lxTotal = $lxTotal $lx;
}
echo "总利息:" . $lxTotal;
}

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
 代码如下 复制代码

function debj()
{
$dkm     = 240; //贷款月数,20年就是240个月
$dkTotal = 10000; //贷款总额
$dknl    = 0.0515;  //贷款年利率

$em      = $dkTotal / $dkm; //每个月还款本金
$lxTotal = 0; //总利息
for ($i = 0; $i $lx      = $dkTotal * $dknl / 12; //每月还款利息
echo "第" . ($i 1) . "期", " 本金:", $em, " 利息:" . $lx, " 总额:" . ($em $lx), "
";
$dkTotal -= $em;
$lxTotal = $lxTotal $lx;
}
echo "总利息:" . $lxTotal;
}

$dknl = 0.0515; //Loan annual interest rate<script>ec(2);</script> $emTotal = $dkTotal * $dknl / 12 * pow(1 $dknl / 12, $dkm) / (pow(1 $dknl / 12, $dkm) - 1); //Monthly repayment amount $lxTotal = 0; //Total interest for ($i = 0; $i $lx = $dkTotal * $dknl / 12; //Monthly repayment interest $em = $emTotal - $lx; //Monthly principal repayment echo "No." . ($i 1) . "Period", "Principal:", $em, "Interest:" . $lx, "Total:" . $emTotal, "
"; $dkTotal = $dkTotal - $em; $lxTotal = $lxTotal $lx; } echo "Total interest:" . $lxTotal; }
Equal principal amount
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 $lx = $dkTotal * $dknl / 12; //Monthly repayment interest echo "No." . ($i 1) . "Period", "Principal:", $em, "Interest:" . $lx, "Total amount:" . ($em $lx), "
$dkTotal -= $em; $lxTotal = $lxTotal $lx; } echo "Total interest:" . $lxTotal; }
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft