C#格式化数值结果表
来源:互联网 发布:推荐好玩网络和页游 编辑:程序博客网 时间:2024/04/19 19:38
C#格式化数值结果表
字符
说明
示例
输出
C货币string.Format("{0:C3}", 2)$2.000D十进制string.Format("{0:D3}", 2)002E科学计数法1.20E+0011.20E+001G常规string.Format("{0:G}", 2)2N用分号隔开的数字string.Format("{0:N}", 250000)250,000.00X十六进制string.Format("{0:X000}", 12)Cstring.Format("{0:000.000}", 12.2)012.200
Strings
There really isn't any formatting within a strong, beyond it's alignment. Alignment works for any argument being printed in a String.Format call.
Numbers
Basic number formatting specifiers:
Output
(Passed
Double 1.42)
(Passed
Double 1.42)
Output
(Passed
Int -12400)
cCurrency{0:c}$1.42-$12,400dDecimal (Whole number){0:d}System.(Passed
Int -12400)
FormatException-12400eScientific{0:e}1.420000e+000-1.240000e+004fFixed point{0:f}1.42-12400.00gGeneral{0:g}1.42-12400nNumber with commas for thousands{0:n}1.42-12,400rRound trippable{0:r}1.42System.
FormatExceptionxHexadecimal{0:x4}System.
FormatExceptioncf90
Custom number formatting:
The group separator is especially useful for formatting currency values which require that negative values be enclosed in parentheses. This currency formatting example at the bottom of this document makes it obvious:
Dates
Note that date formatting is especially dependant on the system's regional settings; the example strings here are from my local locale.
The 'U' specifier seems broken; that string certainly isn't sortable.
Custom date formatting:
Enumerations
Some Useful Examples
String.Format("{0:$#,##0.00;($#,##0.00);Zero}", value);
This will output "$1,240.00" if passed 1243.50. It will output the same format but in parentheses if the number is negative, and will output the string "Zero" if the number is zero.
String.Format("{0:(###) ###-####}", 18005551212);
This will output "(800) 555-1212".变量.ToString()
字符型转换 转为字符串
12345.ToString("n"); //生成 12,345.00
12345.ToString("C"); //生成 ¥12,345.00
12345.ToString("e"); //生成 1.234500e+004
12345.ToString("f4"); //生成 12345.0000
12345.ToString("x"); //生成 3039 (16进制)
12345.ToString("p"); //生成 1,234,500.00%
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- C#格式化数值结果表
- wsdl 和 soap
- FC 10下安装mysql
- CHttpFile实现Get/Post
- Linux的那些事儿(1)----Linux和UNIX以及和Windows的区别
- 非专业心里测试
- C#格式化数值结果表
- 使用Twisted进行socket编程
- delphi 内存流 操作
- 程序员
- Python来完成简单图像处理任务
- delphi 制作资源文件
- wince6.0 下的流驱动开发范例
- 错位的悲伤
- 周期性位置更新