# Financial.Rate(Double, Double, Double, Double, DueDate, Double) 方法

## 定义

``public static double Rate (double NPer, double Pmt, double PV, double FV = 0, Microsoft.VisualBasic.DueDate Due = Microsoft.VisualBasic.DueDate.EndOfPeriod, double Guess = 0.1);``
``static member Rate : double * double * double * double * Microsoft.VisualBasic.DueDate * double -> double``
``Public Function Rate (NPer As Double, Pmt As Double, PV As Double, Optional FV As Double = 0, Optional Due As DueDate = Microsoft.VisualBasic.DueDate.EndOfPeriod, Optional Guess As Double = 0.1) As Double``

NPer
Double

Pmt
Double

PV
Double

FV
Double

Due
DueDate

Guess
Double

Double

#### 例外

`NPer`<= 0。

## 示例

``````Sub TestRate()
Dim PVal, Payment, TotPmts, APR As Double
Dim PayType As DueDate

' Define percentage format.
Dim Fmt As String = "##0.00"
Dim Response As MsgBoxResult
' Usually 0 for a loan.
Dim FVal As Double = 0
' Guess of 10 percent.
Dim Guess As Double = 0.1
PVal = CDbl(InputBox("How much did you borrow?"))
Payment = CDbl(InputBox("What's your monthly payment?"))
TotPmts = CDbl(InputBox("How many monthly payments do you have to make?"))
Response = MsgBox("Do you make payments at the end of the month?", MsgBoxStyle.YesNo)
If Response = MsgBoxResult.No Then
PayType = DueDate.BegOfPeriod
Else
PayType = DueDate.EndOfPeriod
End If
APR = (Rate(TotPmts, -Payment, PVal, FVal, PayType, Guess) * 12) * 100

MsgBox("Your interest rate is " & Format(CInt(APR), Fmt) & " percent.")
End Sub
``````

## 注解

`Rate` 由迭代计算。 从值 `Guess`开始， `Rate` 将循环计算，直到结果准确到 0.00001% 以内。 如果在 `Rate` 20 次尝试后找不到结果，则失败。 如果猜测为 10%， 失败`Rate`，请尝试其他值。`Guess`