views:

39

answers:

3

If I want to display, say, 4 decimal points, what is the correct format?

+6  A: 
String.Format("{0:0.0000}", floatNum);

That will always display four decimal places, regardless of what the value is. Other options can be found here: http://www.csharp-examples.net/string-format-double/

Mark Kinsella
A: 

Notice that it rounds:

decimal d = 1.23456789M;
Console.WriteLine(d.ToString("0.0000"));

// Output: 1.2345

As a format string, it would be:

Console.WriteLine("{0:0.0000}", d);
David
A: 

Personally, I prefer this approach.

floatNum.ToString("N4")
Axeva