不知道为什么会发生这种情况,但利率应该是17.9%,但是工作为19.something%。我已经尝试了很多方法来解决它但无法让它完全正常工作。举个例子,到目前为止,我总共有200欧元。 17.9%的利息应为€35.80。但即将到来的是€38.89任何想法?
Public Class frmFinancePackage
'Interest rate = 17.9%
Const interestRate As Decimal = 0.179
'this method will calculate the compound interest for the
'finance package and calculate payments
Private Sub frmFinancePackage_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
txtGrossTotal.Text = FormatCurrency(runningCost)
End Sub
Private Sub btnCalculate_Click(sender As System.Object, _
e As System.EventArgs) Handles btnCalculate.Click
'Declaring local variables
Dim NumYears As Integer
Dim GrossTotal As Decimal
Dim PaymentDue As Integer
Dim NetTotal As Decimal
'Assigning a value to the numYears variable based on which radio button is checked
'If no radio button is checked a value of 0 is passed
If rdoOneYear.Checked Then
NumYears = 1
ElseIf rdoTwoYears.Checked Then
NumYears = 2
ElseIf rdoThreeYears.Checked Then
NumYears = 3
End If
GrossTotal = runningCost
'Assign a value to NetTotal by calling a function findNetTotal
'pass the variables NumYears and GrossTotal
NetTotal = findNetTotal(NumYears, GrossTotal)
'Assign a value to paymentDue based on what payment frequency radio button is checked
'pass a vaule of 0 if no radio button is checked
If rdoWeekly.Checked Then
PaymentDue = 52 * NumYears
ElseIf rdoMonthly.Checked Then
PaymentDue = 12 * NumYears
ElseIf rdoQuarterly.Checked Then
PaymentDue = 4 * NumYears
End If
'Displaying the results
txtInterest.Text = FormatCurrency(NetTotal - GrossTotal)
txtNetTotal.Text = FormatCurrency(NetTotal)
txtPayment.Text = FormatCurrency(NetTotal / PaymentDue)
btnContinue.Enabled = True
End Sub
'这是查找NetTotal的功能
Private Function findNetTotal(ByVal years As Integer, ByVal total As Decimal) As Decimal
'Declare variables for the function
Dim interest As Decimal
Dim months As Integer = years * 12
'Use a loop to find the net total based on compound interest for the number of years
'compound interst is calculated per month
'return the net total
For i As Integer = 1 To months
interest = total * (interestRate / 12)
total += interest
Next
Return total
End Function
End Class
答案 0 :(得分:0)
我认为您的代码可能是正确的,但您的测试可能不是。当我将以下公式*放入Excel时,它给出了与findNetTotal函数相同的值。
= 200 *(1+(0.179 / 12))^ 12 给出238.8882
当我将代码(常量和findNewTotal)粘贴到本地项目中时,调用findNewTotal为1年,200为总,给出238.88815 ....作为输出,与Excel匹配。
那么,为什么你认为17.9%应该拿出35.80而不是38.89?
*公式来自MS网站的复利:http://support.microsoft.com/kb/141695