惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
T
Tenable Blog
T
Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Security Latest
Security Latest
P
Privacy & Cybersecurity Law Blog
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
P
Palo Alto Networks Blog
TaoSecurity Blog
TaoSecurity Blog
Webroot Blog
Webroot Blog
Spread Privacy
Spread Privacy
O
OpenAI News
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
C
Check Point Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
人人都是产品经理
人人都是产品经理
S
Security @ Cisco Blogs
Scott Helme
Scott Helme
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
T
Troy Hunt's Blog
W
WeLiveSecurity
GbyAI
GbyAI
N
News | PayPal Newsroom
Y
Y Combinator Blog
C
Cisco Blogs
H
Help Net Security
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 【当耐特】
Jina AI
Jina AI
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
云风的 BLOG
云风的 BLOG
小众软件
小众软件
N
News and Events Feed by Topic

博客园 - bobbychen

C++之不带指针类的设计——Boolean .ctor,.cctor 以及 对象的构造过程 C#中virtual 方法和abstract方法的区别 SQL循环插入批量数据 【VS.NET 调试异常】 CLR 无法从 COM 上下文 XXX 转换为 COM 上下文 XXX SQL重复记录查询 String.Format格式说明 HTML特殊字符 - 补遗 【Access】 LEFT OUTER JOIN 关联多表的查询语句 【转帖】C#与C Windows API数据类型对应关系 Visual Studio 进行单元测试时如何附加被测试文件的方法总结 【转帖】C# 与 C++ 数据类型对照 【.Net Compact Framework开发】 使用 Visual Studio 对移动项目进行Unit Testing的方法总结 【转帖】const 与 readonly 的区别 【转帖】解决继承窗体或用户控件时“visual继承当前被禁用,因为基类引用设备特定的组件或包含 p/invoke”问题 PowerDesigner实体模型CDM中关于建立Entity之间关系的备忘 【部署】Visual Studio 2008 打包部署.Net Framework 2.0 应用程序提示需要安装.Net Framework 3.5的解决方法 SQL 使用CONVERT函数 格式化日期 【Winform窗体控件开发】之五 实现类型转换器TypeConverterAttribute
C#数字格式化方法全面解析
bobbychen · 2012-03-14 · via 博客园 - bobbychen

C#数字格式化输出:

int a = 12345678;

C#数字格式化之格式为sring输出

Label1.Text = string.Format("asdfadsf{0}adsfasdf",a);

Label2.Text = "asdfadsf"+a.ToString()+"adsfasdf";

Label1.Text = string.Format("asdfadsf{0:C}adsfasdf",a);//asdfadsf¥1,234.00adsfasdf

Label2.Text = "asdfadsf"+a.ToString("C")+"adsfasdf";//asdfadsf¥1,234.00adsfasdf

double b = 1234.12543;

int a = 12345678;

C#数字格式化之格式为特殊的string样式输出

Label1.Text = string.Format("asdfadsf{0:C}adsfasdf",b);//asdfadsf¥1,234.13adsfasdf

Label2.Text = "asdfadsf"+b.ToString("C")+"adsfasdf";//asdfadsf¥1,234.13adsfasdf

Label1.Text = string.Format("{0:C3}",b);//¥1,234.125

Label2.Text = b.ToString("C3");//¥1,234.125

Label1.Text = string.Format("{0:d}",a);//十进制--12345678

Label2.Text = b.ToString("d");//十进制--相同的类型,转换报错

Label1.Text = string.Format("{0:e}",a);//指数--1.234568e+007

Label2.Text = b.ToString("e");//指数--1.234125e+003

Label1.Text = string.Format("{0:f}",a);//定点数--12345678.00

Label2.Text = b.ToString("f");//定点数--1234.13

Label1.Text = string.Format("{0:n}",a);//数值--12,345,678.00

Label2.Text = b.ToString("n");//数值--1,234.13

Label1.Text = string.Format("{0:x}",a);//十六进制--bc614e

Label2.Text = b.ToString("x");//16--带有小数不能转换,出错

Label1.Text = string.Format("{0:g}",a);//通用为最紧凑--12345678

Label2.Text = b.ToString("g");//通用为最紧凑--1234.12543

Label1.Text = string.Format("{0:r}",a);//转来转去不损失精度--整数不允许用,报错

Label2.Text = b.ToString("r");//转来转去不损失精度--1234.12543

double b = 4321.12543;

int a = 1234;

C#数字格式化之自定义模式输出:

C#数字格式化之"0"描述:占位符,如果可能,填充位

Label1.Text = string.Format("{0:000000}",a);// 001234

Label2.Text = string.Format("{0:000000}",b);// 004321

C#数字格式化之"#"描述:占位符,如果可能,填充位

Label1.Text = string.Format("{0:#######}",a);// 1234

Label2.Text = string.Format("{0:#######}",b);// 4321

Label1.Text = string.Format("{0:#0####}",a);// 01234

Label2.Text = string.Format("{0:0#0000}",b);// 004321

C#数字格式化之"."描述:小数点

Label1.Text = string.Format("{0:000.000}",a);//1234.000

Label2.Text = string.Format("{0:000.000}",b);//4321.125

double b = 87654321.12543;

int a = 12345678;

C#数字格式化之","描述:数字分组,也用于增倍器

Label1.Text = string.Format("{0:0,00}",a);// 12,345,678

Label2.Text = string.Format("{0:0,00}",b);// 87,654,32

Label1.Text = string.Format("{0:0,}",a);// 12346

Label2.Text = string.Format("{0:0,}",b);// 87654

Label1.Text = string.Format("{0:0,,}",a);// 12

Label2.Text = string.Format("{0:0,,}",b);// 88

Label1.Text = string.Format("{0:0,,,}",a);// 0

Label2.Text = string.Format("{0:0,,,}",b);// 0

C#数字格式化之"%"描述:格式为百分数

Label1.Text = string.Format("{0:0%}",a);// 1234567800%

Label2.Text = string.Format("{0:#%}",b);// 8765432113%

Label1.Text = string.Format("{0:0.00%}",a);// 1234567800.00%

Label2.Text = string.Format("{0:#.00%}",b);// 8765432112.54%

C#数字格式化之"abc"描述:显示单引号内的文本

Label1.Text = string.Format("{0:'文本'0}",a);// 文本12345678

Label2.Text = string.Format("{0:文本0}",b);// 文本87654321

C#数字格式化之"/"描述:后跟1要打印字的字符,也用于转移符/n等

Label1.Text = string.Format("/"你好!/"");// "你好!"

Label2.Text = string.Format("[url=file:////c//books//new//we.asp]//c//books//new//we.asp");///c/books/new/we.asp

C#数字格式化之"@"描述:后跟要打印字的字符,

Label1.Text = string.Format(@"""你好!"""); // "你好!"要打印"则需要输入两对才可以

Label2.Text = string.Format(@"/c/books/new/we.asp");///c/books/new/we.asp