日期:2013-10-10  浏览次数:20565 次

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 );