vb.net Visual Basic 贷款利息和本金计算器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13558242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Basic loan interest and principal calculator
提问by Wilber Montes
I'm trying to get the program to output the principal paid out to and the interest paid towards a loan of $5000. No input is take its all been declared already.
我试图让程序输出支付给 5000 美元贷款的本金和支付的利息。没有输入是全部已经声明的。
Private Sub calButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calButton.Click
Dim monthlyPayments As Double
Dim bloanTotal As Double = 5000
Dim rate As Double = 0.005
Dim interest As Double
Dim toPrincipal As Double
Dim toInterest As Double
Dim counter As Integer
Do
'calculate the montly payments.
monthlyPayments =
Financial.Pmt(0.06 / 12, 12, 5000)
TextBox1.Text = monthlyPayments.ToString("C2")
counter = counter + 1 'add one to the counter
interest = bloanTotal * rate 'calculate interest rate from payment that will only count as interest
toInterest = monthlyPayments - interest 'amount of monthly payment going towards interest
toPrincipal = monthlyPayments - toInterest ' amount of monthly payment going towards principal
bloanTotal = bloanTotal - toPrincipal 'new balance after deducing principal from begining balance
Label2.Text = toPrincipal.ToString & " " &
toInterest.ToString &
ControlChars.NewLine ' concatinate principal and interest strings and create a new line
If counter = 12 Then 'exit loop once counter has reached 12 and loan amount has reached zero
Exit Do
End If
Loop
End Sub
采纳答案by Kratz
I believe your problem is that the Financial.Pmtfunction is returning a negative number. Because this is accounting, you are telling the function you have recieved a 5000 loan (positive number) and you will be making payments (negative number). If you do this
我相信您的问题是该Financial.Pmt函数返回一个负数。因为这是会计,所以您告诉函数您已收到 5000 笔贷款(正数)并且您将付款(负数)。如果你这样做
monthlyPayments = Math.Abs(Financial.Pmt(0.06 / 12, 12, 5000))
monthlyPayments = Math.Abs(Financial.Pmt(0.06 / 12, 12, 5000))
then your calculations should work out.
那么你的计算应该可以解决。

