//數字字串不足,前面補0
Response.Write(String.Format("{0:00000}", 123)); // 輸出 00123
Response.Write(String.Format("{0:D5}", 123)); // 輸出 00123

//數字字串不足,前後都補0
Response.Write(String.Format("{0:00000.0000}", 123.45)); // 輸出 00125.4500

//每3位數加逗號
Response.Write(String.Format("{0:0,0}", 0)); // 輸出 00
Response.Write(String.Format("{0:0,0}", 1234567)); // 輸出 1,234,567  //缺點:當數字=0時,會顯示 00
Response.Write(String.Format("{0:N}", 1234567)); // 輸出 1,234,567.00
Response.Write(String.Format("{0:N0}", 1234567)); // 輸出 1,234,567
Response.Write(String.Format("{0:N4}", 1234567)); // 輸出 1,234,567.0000

//電話號碼
Response.Write(String.Format("{0:(###) ####-####}", 88012345678)); // 輸出(880)1234-5678

//金額表示方式
Response.Write(String.Format("{0:C}", 0)); // 輸出 NT$0.00
Response.Write(String.Format("{0:C}", 12345)); // 輸出 NT$12,345.00
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

//百分比
Response.Write(String.Format("{0:0%}", 17 / (float)60)); // 輸出 28%

//到小數2位的百分比
Response.Write(String.Format("{0:0.00%}", 17 / (float)60)); // 輸出 28.33%

//取小數第4位,並對第5位做四捨五入
Response.Write(String.Format("{0:#,0.####}", 1234.56789)); // 1,234.5679

//小數點不足4位不補0
Response.Write(String.Format("{0:0.####}", 1234.567)); // 1234.567


arrow
arrow
    全站熱搜

    Roger 發表在 痞客邦 留言(0) 人氣()