http://msdn.microsoft.com/library/dotnet/cpguide/cpconstandardnumericformatstrings.htm(这个是连接url)
standard numeric format strings are used to return commonly used numeric string types. they take the form x0, where x is the format specifier and 0 is the precision specifier. the format specifier can be one of the seven built-in format characters that define the most commonly used .net framework numeric format types. the precision specifier controls the number of significant digits or zeros to the right of a decimal.
format character description default return format (without precision specifier)
c or c currency format $xx,xx.xx
($xx,xxx.xx)
d or d decimal format [-]xxxxxxx
e or e scientific (exponential) format [-]x.xxxxxxe+xxx
[-]x.xxxxxxe+xxx
[-]x.xxxxxxe-xxx
[-]x.xxxxxxe-xxx
f or f fixed-point format [-]xxxxxxx.xx
g or g general format variable. either general or scientific.
n or n number format [-]xx,xxx.xx
x or x hexadecimal format variable. returns the minimum hexadecimal representation.
currency format
the "c" format specifier causes the format method to return a string representing the number as a currency value. the currency symbols used (currency symbol, decimal separator, group separator, and so on) are determined by the current culture if a numberformatinfo object is not provided. an integer following the "c" determines the number of decimal places that are displayed. if no number is provided, two digits are shown after the decimal separator.
[c#]
int myint = 12345;
myint.format( "c", null );
// returns the currency string "$12,345.00"
myint.format( "c3", null );
// returns the exponential string "$12,345.000"
decimal format
the "d" format specifier converts the value from an integer to a base 10 (decimal) number. only integral types support the "d" format code. a negative symbol is prefixed to the result if the value is negative. you can also specify the minimum number of decimal digits to display using a precision specifier.
[c#]
int myint = 123;
myint.format( "d5", null );
// returns the decimal string "00123"
myint.format( "d2", null );
// returns the decimal string "123"
exponential format
the “e” format specifier causes the format method to return a string formatted as a scientific (or exponential) number. the precision specifier determines the number of digits after the decimal point. the case of the exponent format character ("e" or "e") determines the case of the exponent symbol.
[c#]
int myint = 12345;
myint.format( "e", null );
// returns the exponential string "1.234500e+004"
myint.format( "e3", null );
// returns the exponential string "1.235e+004"
fixed point format
the "f" format specifier inserts a decimal to the right of a nondecimal number followed by the number of zeros specified by the precision specifier. if no precision specifier is supplied, two zeros will be inserted.
[c#]
int myint = 12345;
myint.format( "f", null );
// returns the exponential string "12345.00"
myint.format( "f3", null );
// returns the exponential string "12345.000"
general format
the "g" format specifier converts a numeric value to either fixed point ("f") or scientific format ("e"). this specifier returns the most compact string representation for a given number.
[c#]
int myint = 12345;
myint.format( "g", null );
// returns the exponential string "12345"
myint.format( "g3", null );
// returns the exponential string "123e4"
number format
the "n" format specifier converts a numeric value to the form "[-]d,ddd,ddd.dd". a decimal is inserted at the far right of the number followed by the number of zeros specified by the format specifier. if no precision specifier is supplied, two zeros are inserted.
[c#]
int myint = 12345;
myint.format( "n", null );
// returns the exponential string "12,345.00"
myint.format( "n3", null );
// returns the exponential string "12,345.000"
hexadecimal format
the "x" format specifier converts a numeric value to a hexadecimal (base 16) string representation. the precision specifier determines the minimum number of digits returned. if no precision specifier is supplied, the minimum number of digits needed to represent the value is returned; otherwise, the number will be padded with zeros to meet the number of digits required by the precision specifier.
[c#]
int myint = 12345;
myint.format( "x", null );
// returns the exponential string "3039"
myint.format( "x3", null );
// returns the exponential string "3039"