Visual Basic贷款利息和本金计算器

时间:2012-11-26 03:17:32

标签: vb.net visual-studio-2010

我试图让计划输出支付的本金和支付的利息 贷款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

1 个答案:

答案 0 :(得分:0)

我相信你的问题是Financial.Pmt函数返回一个负数。因为这是会计,你告诉你已经收到5000贷款(正数)的功能,你将支付(负数)。如果你这样做

monthlyPayments = Math.Abs(Financial.Pmt(0.06 / 12, 12, 5000))

然后你的计算应该成功。