C#中ToString数据类型格式大全(千分符)总结


当前第2页 返回上一页

(1) int i=12345;

1

2

3

4

this.textBox1.Text=i.ToString();

//结果 12345(this指当前对象,或叫当前类的实例)

this.textBox2.Text=i.ToString("d8");

//结果 00012345

(2) int i=123;

1

2

3

4

5

6

7

double j=123.45;

string s1=string.Format("the value is {0,7:d}",i);

string s2=string.Format("the value is {0,7:f3}",j);

this.textBox1.Text=s1 ;

//结果 the value is 123

this.textBox2.Text=s2;

//结果 the value is 123.450

(3)double i=12345.6789;

1

2

3

this.textBox1.Text=i.ToString("f2"); //结果 12345.68

this.textBox2.Text=i.ToString("f6");

//结果 12345.678900

(4)double i=12345.6789;

1

2

this.textBox1.Text=i.ToString("n"); //结果 12,345.68

this.textBox2.Text=i.ToString(“n4”); //结果 12,345.6789

(5)double i=0.126;

1

2

3

string s=string.Format("the value is {0:p}",i);

this.textBox1.Text=i.ToString("p"); //结果 12.6%

this.textBox2.Text=s; //结果 the value is 12.6%

(6) DateTime dt =new DateTime(2003,5,25);

1

2

3

4

5

this.textBox1.Text=dt.ToString("yy.M.d");

//结果 03.5.25

this.textBox2.Text=dt.ToString(“yyyy年M月”);

//结果 2003年5月

Convert.ToDateTime("2005/12/22 22:22:22").ToString("yyyy/MM/dd HH:mm:ss")"2005/12/22 22:22:22"

(7) int i=123;

1

2

3

4

5

double j=123.45;

string s=string.Format("i:{0,-7},j:{1,7}",i,j);

//-7表示左对齐,占7位

this.textBox1.Text=s ;

//结果i:123 ,j: 123.45

以上就是C#中ToString数据类型格式大全(千分符)总结的详细内容!

返回前面的内容

相关阅读 >>

C# 2.0 specification (四)

C#兼容各大浏览器的文件下载实例详解

详解C#读取xml多级子节点的示例代码

具体介绍C#使用selenium+phantomjs抓取数据的案例(图文)

C#计算标准偏差相当于excel中的stdev函数的代码案例

带你了解C#中的构造函数

C#中实现退出程序后自动重新启动程序的示例代码分享

浅谈C#方法的六种参数

使用C#实现发送自定义的html格式邮件的代码案例

C#灵活使用类的方法分享

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...