People often struggle to use the right kind of numeric format specifiers. So here is the list of them once again (they can be found in any C# for beginners book) or on
msdn.
C[n] - Currency
D[n] - Decimal
E[n] or e[n] - Exponent
F[n] - Fixed point
G[n] - General
N[n] - Number
X[n] or x[n] - Hex
n in all cases are the precision specifiers.
Examples - Compare various output when
Console.WriteLine
is used with an
integer
value.
Console.WriteLine("{0:C4}", 5);
Console.WriteLine("{0:D4}", 5);
Console.WriteLine("{0:E4}", 5);
Console.WriteLine("{0:F4}", 5);
Console.WriteLine("{0:G4}", 5);
Console.WriteLine("{0:N4}", 5);
Console.WriteLine("{0:X4}", 5);
Comparision when
Console.WriteLine
is used with a
double
value.
double l = 5.00;
Console.WriteLine("{0:C4}", l);
Console.WriteLine("{0:N4}", l);
Console.WriteLine("{0:G4}", l);
Console.WriteLine("{0:F4}", l);
Console.WriteLine("{0:F4}", l);
Cheers