Last active
May 5, 2018 15:32
-
-
Save nemoTyrant/fd43817e9e7a158a709a70861e85f2da to your computer and use it in GitHub Desktop.
等额本息还款计划表
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $P = 490000; // 本金 | |
| $R = 0.0539 / 12; // 月利率 | |
| $N = 120; // 还款期数 | |
| $startDate = "2016-2-7"; | |
| $timestamp = strtotime($startDate); | |
| $M = round($P * ($R * pow(1 + $R, $N)) / (pow(1 + $R, $N) - 1), 2); | |
| echo "每月还款为 " . $M . " 元\n"; | |
| echo "日期\t\t本金\t\t利息\t\t剩余本金\n"; | |
| for ($i = 0; $i < $N; $i++) { | |
| $mt = floor($P * $R * 100) / 100; // 当月利息 | |
| $mp = $M - $mt; // 当月本金 | |
| $P = $P - $mp; | |
| $mpPad = strlen(number_format($mp, 2)) < 7 ? "\t" : ""; | |
| $mtPad = strlen(number_format($mt, 2)) < 7 ? "\t" : ""; | |
| printf("%s\t%s{$mpPad}\t%s{$mtPad}\t%s\n", date('Y-m-d', $timestamp), number_format($mp, 2), number_format($mt, 2), number_format($P, 2)); | |
| $timestamp = strtotime("+1 month", $timestamp); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
命令行下使用