Question

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

Was it helpful?

Solution

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/

OTHER TIPS

Personally, I prefer this approach.

floatNum.ToString("N4")

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top