国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

數(shù)值變換時(shí)的格式化字符舉例

2024-07-21 02:16:37
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
http://msdn.microsoft.com/library/dotnet/cpguide/cpconstandardnumericformatstrings.htm(這個(gè)是連接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"
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 丰都县| 阿瓦提县| 克东县| 茌平县| 平遥县| 和平区| 宝坻区| 会宁县| 天门市| 连江县| 兰考县| 开阳县| 广安市| 塘沽区| 祥云县| 景洪市| 荣成市| 确山县| 平阴县| 当涂县| 南郑县| 塔城市| 梅州市| 中方县| 乌鲁木齐县| 福贡县| 会昌县| 西平县| 蒲江县| 阜康市| 南郑县| 江陵县| 洞头县| 琼中| 舞钢市| 台安县| 东平县| 苍溪县| 琼海市| 延庆县| 泗洪县|