你可以使用這個類:
public class Financial
{
#region Methods
public static decimal IPmt(decimal Rate, decimal Per, decimal NPer, decimal PV, decimal FV, FinancialEnumDueDate Due)
{
decimal num;
if (Due != FinancialEnumDueDate.EndOfPeriod)
{
num = 2;
}
else
{
num = 1;
}
if ((Per <= 0) || (Per >= (NPer + 1)))
{
//Argument_InvalidValue1=
throw new ArgumentException("Argument 'Per' is not a valid value.");
}
if ((Due != FinancialEnumDueDate.EndOfPeriod) && (Per == 1))
{
return 0;
}
decimal pmt = Pmt(Rate, NPer, PV, FV, Due);
if (Due != FinancialEnumDueDate.EndOfPeriod)
{
PV += pmt;
}
return (FV_Internal(Rate, Per - num, pmt, PV, FinancialEnumDueDate.EndOfPeriod) * Rate);
}
public static decimal PPmt(decimal Rate, decimal Per, decimal NPer, decimal PV, decimal FV, FinancialEnumDueDate Due)
{
if ((Per <= 0) || (Per >= (NPer + 1)))
{
throw new ArgumentException("Argument 'Per' is not valid.");
}
decimal num2 = Pmt(Rate, NPer, PV, FV, Due);
decimal num = IPmt(Rate, Per, NPer, PV, FV, Due);
return (num2 - num);
}
static decimal FV_Internal(decimal Rate, decimal NPer, decimal Pmt, decimal PV, FinancialEnumDueDate Due)
{
decimal num;
if (Rate == 0)
{
return (-PV - (Pmt * NPer));
}
if (Due != FinancialEnumDueDate.EndOfPeriod)
{
num = 1 + Rate;
}
else
{
num = 1;
}
decimal x = 1 + Rate;
decimal num2 = (decimal)Math.Pow((double)x, (double)NPer);
return ((-PV * num2) - (((Pmt/Rate) * num) * (num2 - 1)));
}
static decimal Pmt(decimal Rate, decimal NPer, decimal PV, decimal FV, FinancialEnumDueDate Due)
{
decimal num;
if (NPer == 0)
{
throw new ArgumentException("Argument NPer is not a valid value.");
}
if (Rate == 0)
{
return ((-FV - PV)/NPer);
}
if (Due != FinancialEnumDueDate.EndOfPeriod)
{
num = 1 + Rate;
}
else
{
num = 1;
}
decimal x = Rate + 1;
decimal num2 = (decimal)Math.Pow((double)x, (double)NPer);
return (((-FV - (PV * num2))/(num * (num2 - 1))) * Rate);
}
#endregion Methods
}
我完全-不-A-VB-用戶的猜測是,財政庫可能存儲處理內部正確,但我不會賭。你需要檢查內部處理是否一致,然後才根據返回類型對其進行譴責。 – Matchu 2010-04-08 22:58:09
我的投票是布爾 - 你要麼有錢,要麼你沒有;-) – scunliffe 2010-04-08 22:58:35
對VB和C來說是一樣的# – Dryadwoods 2010-04-08 22:59:18