Response.Write(string.Format("{0}", "ss", "dd"));//輸出ss
Response.Write(String.Format("{0:0000}", 157)); // 輸出 0157
Response.Write(String.Format("{0:0000.0000}", 157.42)); // 輸出 0157.4200
Response.Write(String.Format("{0:0,0}", 38560)); // 輸出 38,560
// 電話號碼 格式化
Response.Write(String.Format("{0:(###) ###-####}", 8012105552)); // 輸出 (801) 210-5552
// 符號可以更換
Response.Write(String.Format("{0:¥#,##0.00;($#,##0.00);Zero}", 0)); // 輸出 Zero
Response.Write(String.Format("{0:¥#,##0.00;($#,##0.00);Zero}", 1234.50)); //輸出 ¥1,234.50
1、字符串的百分比表示,將Double類型表示成百分比字符串
Double d=0.758;
String sPercent=d.ToString("p");
結果:sPercent=75.8%;
2、字符串四捨五入保留小數點後的位數
Double d=0.758923;
//保留小數點後兩位
String s=d.ToString("0.00");
結果:s=0.76