المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Character Format



C# Programming
01-25-2010, 01:10 PM
Hi all,

I am having difficulties formatting the output of the following writeline statement.

Console.WriteLine("CYLINDER1:\n RADIUS:"+ t1.Rad+"\n LENGTH:"+ t1.Len+"\n AREA:"+ t1.findArea()+"\n VOLUME:" + t1.findVolume());

Both radius and length are of type double, and both methods, findArea() and findVolume(), are defined as follows:

public double findArea()
{
return 2*(Math.PI * radius * radius) + 2*(Math.PI * radius * length);
}

public double findVolume()
{
return Math.PI *(radius * radius *length);
}

I would like the outputs of Area and Volume to have 4 numbers behind the decimal place. Please take a look and see what I'd have to change to make it output what I want. Thank you in advance for your help.