Format int value in decimal format with Decimal ("D") Format in CSharp

Description

The following code shows how to format int value in decimal format with Decimal ("D") Format.

Example


using System;//  w  w w. ja va  2s  .c  o  m

public class MainClass {     
   static void Main()
   {
        int value; 
        
        value = 12345;
        Console.WriteLine(value.ToString("D"));
        // Displays 12345
        Console.WriteLine(value.ToString("D8"));
        // Displays 00012345 
        
        value = -12345;
        Console.WriteLine(value.ToString("D"));
        // Displays -12345
        Console.WriteLine(value.ToString("D8"));
        // Displays -00012345
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var