[double]格式化输出

double数据类型常见的格式化方法如下:

double pi =3.1415926;

(F)Fixed point:string str1=pi.toString("f1");//保留一位小数 四舍五入 结果:3.1

(F)Fixed point:string str2=pi.toString("f2");//保留两位小数,四舍五入 下面一次类推 结果:3.14

(F)Fixed point:string str2=pi.toString("fn");//保留n位小数,四舍五入 

(N)Number:string str2=pi.toString("N");//保留 结果:3.14

(G)General (default):string str2=pi.toString("G");//保留 结果:3.1415926

(P)Percent:string str2=pi.toString("P");//保留 结果:314.16%

(E)Scientific:string str2=pi.toString("E");//保留 结果E:3.141593E+000

(C)Currency:string str2=pi.toString("C");//保留 结果:¥3.14
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章