Thread: Int.ToString

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    Int.ToString

    Hello everyone,


    What is the function of "D10" when use it as input parameter to Int.ToString? For example, someIntValue.ToString ("D10")? I can not find any document about this format input parameter from MSDN. Any documents?


    thanks in advance,
    George

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    In "D10" the "D" is the format specifier which in this case is decimal. The "10" is the precision specifier which is the minimum number of digits in the result and is normally padded with zeros to the left to produce the number of digits given by the precision specifier.

    Code:
    using System;
    public class George2
    {
    	public static void Main()
    		{
    		int value = 12345;
    		Console.WriteLine(value.ToString("D"));
    		Console.WriteLine(value.ToString("D10"));
    		value = -12345;
    		Console.WriteLine(value.ToString("D"));
    		Console.WriteLine(value.ToString("D10"));
    	}
    }
    Output:
    12345
    0000012345
    -12345
    -0000012345

Popular pages Recent additions subscribe to a feed