VB “Financial.Pmt” equivalent in C#?

前端 未结 4 1103
深忆病人
深忆病人 2021-01-13 23:30

There is a built in function from the Microsoft.VisualBasic assembly. I can use it in VB like this:

Financial.Pmt((dAPR / 100) / 12, iNumberOfPayments, dLoan         


        
4条回答
  •  悲哀的现实
    2021-01-14 00:21

    Like this:

    using System;
    using Microsoft.VisualBasic;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                double dAPR = 2;
                Int32 iNumberOfPayments = 12;
                double dLoanAmount = 10000;
                Console.WriteLine(Financial.Pmt((dAPR / 100) / 12, iNumberOfPayments, dLoanAmount, 0, DueDate.EndOfPeriod) * -1);
                Console.ReadLine();
            }
        }
    }
    
    • Like Joel says, add a reference to the Microsoft.VisualBasic assembly.
    • Like Rup says in a comment, you have to provide the defaults to the 4th and 5th arguments.

    Do use Microsoft.VisualBasic from C# when appropriate. It's a fully supported core library in .Net and it contains some useful financial functions.

提交回复
热议问题