前提・実現したいこと
元利均等のボタンを押されたら元利均等で処理を行う。
とりあえず、var_dumpで値を出したい。
変数名
借入金額:$money
返済方式、返済頻度(とりあえず無視)
金利:$interest_year
返済期間:$return
元利均等の計算式:上記画像
発生している問題エラーメッセージ
var_dumpでとりあえず出したい。
元利均等の公式を見ても全くわかりません。
元金均等は出せました。あとはループ処理で本格化を考えています。
該当のソースコード
PHP
//errorチェック $error = ["金額が入力されていません","半角英数字で入力してください", "金利が入力されていません","返済期間の欄が入力されていません"]; //定義されていません対策 $money = ""; $interest_year = ""; $return = ""; //入力値チェック if(empty($_POST["money"]) && isset($_POST["money"])){ $money_empty = $error[0]; }else{ if(isset($_POST["money"]) && isset($_POST["interest_year"]) && isset($_POST["return"])){ $money = $_POST["money"] * 10000; $original_money = $_POST["money"] * 10000; $interest_year = $_POST["interest_year"]; $return = $_POST["return"]; } if(empty($_POST["interest_year"]) && isset($_POST["interest_year"])){ $interest_error = $error[2]; } if(empty($_POST["return"]) && isset($_POST["return"])){ $return_error = $error[3]; } if(preg_match('/^[^ -~。-゚\x00-\x1f\t]+$/u', $money) && !is_numeric($money)){ //全角だったらここに来る $zenkaku = $error[1]; } if(preg_match('/^[^ -~。-゚\x00-\x1f\t]+$/u', $interest_year) && !is_numeric($interest_year)){ //全角だったらここに来る $zenkaku = $error[1]; }if(preg_match('/^[^ -~。-゚\x00-\x1f\t]+$/u', $return) && !is_numeric($return)){ //全角だったらここに来る $zenkaku = $error[1]; } //if文で元利均等か元金均等か判断する処理 //元利均等の処理 $a = $money * ($interest_year / 100 / 12 ) / pow((1 - (1 + $interest_year / 100 / 12)),-$return * 12); $a = var_dump($a); /*for($i = 0; $i < $return; $i++){ $money = ($money * $interest_year) / 1 - pow(($interest_year),$return);//1回目の残高元 $money = floor($money); var_dump($money); }*/ //元金均等の処理:表示結果OK /*$count = 1; for($i = 1 ;$i < $return * 12; $i++){ $a = $money / ($return * 12) + ($money - $money / ($return * 12) * ($i - 1)) * ($interest_year / 12); $count++; var_dump($count); }*/ } //切り捨て //切り上げ //四捨五入
html <!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>家計簿</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/loan.css"> </head> <body> <?php //家計簿の消費税計算画面 ?> <header> <ul> <li><a href="input.php">入力</a></li> <li><a href="index.php">カレンダー</a></li> <li>レポート</li> <li><a href="convenient.php">便利機能</a></li> <li>その他</li> </ul> </header><br> <h1>ローン返済</h1> <form action="" method="post"> <table> <tr> <th>借入金額</th><td><input type="text" name="money">万円</td> </tr> <tr> <th>返済方式</th> <div class="radio"> <td><input type="radio" checked class="radio-input" id="radio-01" name="avg" value="interest"> <label for="radio-01">元利均等</label> <input type="radio" class="radio-input" id="radio-02" name="avg" value="principal"> <label for="radio-02">元金均等</label> 端数<select name="round" id="" class="cp_ipselect"> <option value="floor">切り捨て</option> <option value="round">四捨五入</option> <option value="ceil">切り上げ</option> </select> </td> </div> </tr> <tr> <th>返済頻度</th> <div class="radio"> <td> <input type="radio" checked class="radio-inputs" id="radio-1" name="every" value="month"> <label for="radio-1">毎月</label> <input type="radio" class="radio-inputs" id="radio-2" name="every" value="half_year"> <label for="radio-2">半年毎</label> <input type="radio" class="radio-inputs" id="radio-3" name="every" value="year"> <label for="radio-3">毎年</label> </td> </div> </tr> <tr> <th>金利</th><td><input type="text" name="interest_year">%(年利)</td> </tr> <tr> <th>返済期間</th><td><input type="text" name="return">年 <select name="return_month" id=""> <?php for($i = 0;$i < 12;$i++):?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php endfor;?> </select>ヵ月 </td> </tr> <tr><?php //入力エラー?> <th></th> <td class="text-danger"> <?php if(isset($money_empty)){echo $money_empty;} elseif(isset($zenkaku)){echo $zenkaku;} elseif(isset($interest_error)){echo $interest_error;} elseif(isset($return_error)){echo $return_error;} ?> </td> </tr> </table> <input type="submit" value="計算する" class="btn btn-info btn-lg"> </form> <hr> <h2>ローン返済(結果)</h2> <table class="loan_h2"> <tr> <th>回数</th><th>年/月</th><th>返済総額</th><th>元金文</th><th>利息分</th><th>借入残高</th> </tr> <tr> <td></td><td></td><td></td><td></td><td></td><td></td> </tr> </table>
試したこと
公式を見て式を当てはめてみたのですが、間違っているような気がします。
主にここを見ていただければ大丈夫です。
$a = $money * ($interest_year / 100 / 12 ) / pow((1 - (1 + $interest_year / 100 / 12)),-$return * 12);
var_dump($a);
回答1件
あなたの回答
tips
プレビュー