Address: http://www.cnblogs.com/bignjl/archive/2011/01/14/1935645.html
format Specifier Declaration example output
C Currency 2.5.ToString ("C") ¥2.50
D decimal number 25.ToString ("D5") 00025
e-Scientific 25000.ToString ("E") 2.500000E+005
F fixed point 25.ToString ("F2") 25.00
G Regular 2.5.ToString ("G") 2.5
N Digital 2500000.ToString ("n") 2,500,000.00
X hex 255.ToString ("x") FF
String.Format formatting examples for C #
Stringstr1 =string. Format ("{0:n1}", 56789); result:56,789.0
STRINGSTR2 =string. Format ("{0:n2}", 56789); result:56,789.00
STRINGSTR3 =string. Format ("{0:n3}", 56789); result:56,789.000
Stringstr8 =string. Format ("{0:f1}", 56789); result:56789.0
STRINGSTR9 =string. Format ("{0:f2}", 56789); result:56789.00
Stringstr11 = (56789/100.0). ToString ("#.##"); result:567.89
Stringstr12 = (56789/100). ToString ("#.##"); result:567
C or C
Currency
Console.Write ("{0:c}", 2.5); $2.50
Console.Write ("{0:c}",-2.5); ($2.50)
D or D
Decimal number
Console.Write ("{0:d5}", 25); 00025
E or E
Scientific type
Console.Write ("{0:e}", 250000); 2.500000E+005
F or F
Fixed point
Console.Write ("{0:f2}", 25); 25.00
Console.Write ("{0:f0}", 25); 25
G or G
Conventional
Console.Write ("{0:g}", 2.5); 2.5
N or N
Digital
Console.Write ("{0:n}", 2500000); 2,500,000.00
X or X
Hexadecimal
Console.Write ("{0:x}", 250); FA
Console.Write ("{0:x}", 0xFFFF); FFFF
Build wheels: C #. ToString () formatting