MSDN中有关于String.Format()函数的解释的,楼主不妨参考一下。 ------------------------------------------------------You can format numeric results by using the String.Format method, or through the Console.Write method, which calls String.Format. The format is specified by using format strings. The following table contains the supported standard format strings. The format string takes the following form: Axx, where A is the format specifier and xx is the precision specifier. The format specifier controls the type of formatting applied to the numeric value, and the precision specifier controls the number of significant digits or decimal places of the formatted output. For more information about standard and custom formatting strings, see Formatting Overview. For more information about the String.Format method, see String..::.Format.Character Description Examples Output
C or c Currency Console.Write("{0:C}", 2.5);Console.Write("{0:C}", -2.5); $2.50($2.50)
D or d Decimal Console.Write("{0:D5}", 25); 00025
E or e Scientific Console.Write("{0:E}", 250000); 2.500000E+005
F or f Fixed-point Console.Write("{0:F2}", 25);Console.Write("{0:F0}", 25); 25.0025
G or g General Console.Write("{0:G}", 2.5); 2.5
N or n Number Console.Write("{0:N}", 2500000); 2,500,000.00
X or x Hexadecimal Console.Write("{0:X}", 250);Console.Write("{0:X}", 0xffff); FAFFFF
------------------------------------------------------You can format numeric results by using the String.Format method, or through the Console.Write method, which calls String.Format. The format is specified by using format strings. The following table contains the supported standard format strings. The format string takes the following form: Axx, where A is the format specifier and xx is the precision specifier. The format specifier controls the type of formatting applied to the numeric value, and the precision specifier controls the number of significant digits or decimal places of the formatted output. For more information about standard and custom formatting strings, see Formatting Overview. For more information about the String.Format method, see String..::.Format.Character
Description
Examples
Output
C or c
Currency
Console.Write("{0:C}", 2.5);Console.Write("{0:C}", -2.5);
$2.50($2.50)
D or d
Decimal
Console.Write("{0:D5}", 25);
00025
E or e
Scientific
Console.Write("{0:E}", 250000);
2.500000E+005
F or f
Fixed-point
Console.Write("{0:F2}", 25);Console.Write("{0:F0}", 25);
25.0025
G or g
General
Console.Write("{0:G}", 2.5);
2.5
N or n
Number
Console.Write("{0:N}", 2500000);
2,500,000.00
X or x
Hexadecimal
Console.Write("{0:X}", 250);Console.Write("{0:X}", 0xffff);
FAFFFF
Label1.Text = string.Format("{0:C}",1002000); // 注意没有引号
Label2.Text = string.Format("{0:N}",1002000); // ...
lblText.Text = string.Format("{0:C2}", 12.345); //¥12.35