To format numeric data : Number format « Data Type « C# / CSharp Tutorial






WriteLine("format string", arg0, arg1, ... , argN);

Format specifiers take this general form:

{argnum, width: fmt}
  1. argnum specifies the number of the argument (starting from zero) to display.
  2. width specifies the minimum width of the field
  3. fmt specifies the format
  1. Both width and fmt are optional.
  2. {0} indicates arg0,
  3. {1} specifies arg1, and so on.








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