Help with C# -- Rounding
Hi all,
I'm taking a course in C# and I can't figure out how to get my values (in red) to round to 2 digits. I've searched the internet and I know that Math.round() is the way to do it, in theory, but I can't figure out how to actually implement it into my program, i.e., where to put it and in what format.
If anyone can help, I'd certainly appreciate it!
Thanks,
Rich
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double pv, interestrate, bal, pp, pmt, mir, interestpaid;
int term;
Console.WriteLine("Enter your interest rate in % form ");
interestrate = double.Parse(Console.ReadLine());
Console.WriteLine("Enter your term, in months ");
term = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the amount borrowed ");
pv = double.Parse(Console.ReadLine());
mir = interestrate / 1200;
interestpaid = mir * pv;
pmt = pv * (interestrate / (1 - (1 / ((Math.Pow((1 + mir), term))))));
bal = pv - pmt;
pp = pmt - interestpaid;
Console.WriteLine("Payment Amount Interest Paid Principle Paid New Balance ");
Console.WriteLine(pmt + " " + interestpaid + " " + interestpaid + " " + bal);
}
}
}
|