[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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.