Compute the regular payments for a loan using decimal values in CSharp
Description
The following code shows how to compute the regular payments for a loan using decimal values.
Example
//from w w w.j a v a 2 s .co m
using System;
public class RegPay {
public static void Main() {
decimal Principal; // original principal
decimal IntRate; // interest rate as a decimal, such as 0.075
decimal PayPerYear; // number of payments per year
decimal NumYears; // number of years
decimal Payment; // the regular payment
decimal numer, denom; // temporary work variables
double b, e; // base and exponent for call to Pow()
Principal = 10200.00m;
IntRate = 0.0175m;
PayPerYear = 112.0m;
NumYears = 15.0m;
numer = IntRate * Principal / PayPerYear;
e = (double) -(PayPerYear * NumYears);
b = (double) (IntRate / PayPerYear) + 1;
denom = 1 - (decimal) Math.Pow(b, e);
Payment = numer / denom;
Console.WriteLine("Payment is {0:C}", Payment);
}
}
The code above generates the following result.