Formatting : Zero / Digit placeholder
Example :
double myDouble = 33.945;
Console.WriteLine(myDouble.ToString("#.0000")); //Output = 33.9450
Console.WriteLine(myDouble.ToString("#.####")); //Output = 33.945
Console.WriteLine(myDouble.ToString("000")); //Output = 034
Console.WriteLine(myDouble.ToString("###")); //Output = 34
The overloaded ToString-method converts the double to its equivalent string representation, using the specified format.
- Zero placeholder [0]
In the first example the zero placeholders after the comma make sure that there are 4 digits printed in the output. Example 3 shows padding at the other side. - Digit placeholder [#]
This specifier never displays the '0' character if no significant digit is in place (no padding). See example 2 and 4.
DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString("dddd d MMMM yyyy"));
Interesting links for standard/custom formatting :
0 Comments:
Post a Comment
<< Home