Format number: C, D9, E, F3, N, X, x : Number format « Data Type « C# / CSharp Tutorial





using System;

class MainClass
{
  public static void Main(string[] args)
  {
    Console.WriteLine("C format: {0:C}", 99989.987);
    Console.WriteLine("D9 format: {0:D9}", 99999);
    Console.WriteLine("E format: {0:E}", 99999.76543);
    Console.WriteLine("F3 format: {0:F3}", 99999.9999);
    Console.WriteLine("N format: {0:N}", 99999);
    Console.WriteLine("X format: {0:X}", 99999);
    Console.WriteLine("x format: {0:x}", 99999);

  }
}
C format: $99,989.99
D9 format: 000099999
E format: 9.999977E+004
F3 format: 100000.000
N format: 99,999.00
X format: 1869F
x format: 1869f










2.55.Number format
2.55.1.To format numeric data
2.55.2.Numeric Formatting: Decimal ({0:D}, {0:D7})
2.55.3.Numeric Formatting: Fixed-Point ({0:F}, {0:F0}, {0:F5})
2.55.4.Numeric Formatting: General ({0:G}, {0:G7}, {0:G4})
2.55.5.Numeric Formatting: Number ({0:N}, {0:N4})
2.55.6.Numeric Formatting: Scientific (Exponential) ({0:E}, {0:E10}, {0:e4})
2.55.7.Custom Numeric Formatting: Decimal Point ({0:#####.000}, {0:##.000})
2.55.8.Custom Numeric Formatting: Digit or Space Placeholder ({0:#####}, {0:###})
2.55.9.Custom Numeric Formatting: Digit or Zero Placeholder ({0:000})
2.55.10.Custom Numeric Formatting: Escapes and Literals ({0:###\\#})
2.55.11.Custom Numeric Formatting: Exponential Notation ({0:###.000E-00}, {0:#.0000000E+000})
2.55.12.Custom Numeric Formatting: Group Separator ({0:##,###}, {0:##,000.000})
2.55.13.Custom Numeric Formatting: Number Prescaler ({0:000,,,.###})
2.55.14.Custom Numeric Formatting: Percent Notation ({0:##.000%})
2.55.15.Custom Numeric Formatting: Section Separator ({0:###.00;0;(###.00)})
2.55.16.Format number: C, D9, E, F3, N, X, x