我正在编写一个抵押计算器,它将填充 DataGridView 所有付款以及每次付款的利息和本金。然后最后一列是付款后的余额。
这是问题所在:
按揭付款、利息和本金计算都很好,但由于某种原因,余额计算似乎错误,因为在付款期结束时仍有大量余额。
我的代码可能很草率,因为我还是 vb 的新手。事实上,这是我的第一堂课。
Private Sub AmortButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmortButton.Click 'initiate click event'
Dim Amt As Double = Amount.Text() 'read in amount'
Dim Intr As Double = Intrest.Text() 'read in intrest'
Dim Yrs As Double = Term.Text() 'read in years'
Dim payment As Double = (Yrs * 12) 'convert years to payment periods
'
Dim IntrDec As Double = ((Intr / 100) / 12) 'convert APR to monthly rate as a decimal'
Dim TempAmt As Double = Amt 'setting Temperory balance
For i As Double = 1 To payment Step i + 1 'setting for-loop paramaters'
Dim MP = Math.Round((Pmt(IntrDec, payment, Amt) * -1), 2) 'calculate Mortgage payment'
Dim IP = Math.Round((IPmt(IntrDec, i, payment, Amt) * -1), 2) 'calculate Intrest paid'
Dim PP = Math.Round((PPmt(IntrDec, i, payment, Amt) * -1), 2) 'calculate priciple paid
Amt = Amt - PP 'setting new balance'
Dim RM = Math.Round((Amt), 2) 'rounding balance to two decimals'
AmortTable.Rows.Add(i, MP, IP, PP, RM) 'adding row entry to table'
Next 'end for-loop'