The ToString() method can be immensely useful when wanting to format a
numeric value. To do so, simply pass in your formatting string as a parameter
when calling ToString(), take the following example:
double x = 12.3456789;
Console.WriteLine(x.ToString("0")); //12
Console.WriteLine(x.ToString("0.0")); //12.3
Console.WriteLine(x.ToString("0.00")); //12.35
Console.WriteLine(x.ToString("0.000")); //12.346
http://msdn.microsoft.com/library/de...classtopic.asp
gives some more details on some of the other options you can use when
specifying a formatting string.
Brendan
"Homer Simpson" wrote:
Hi,
I'm looking for a way to format the output of my double value. For example,
the result of a calculation may be 12.3456789 but I want to display 12.346
(three decimal places of precision). How do I do this?
Thanks,
Scott