六月 19
C#:
-
前面補0的數字字串
-
String.Format("{0:0000}", 157); // 輸出 0157
-
-
前後都補0的數字字串
-
String.Format("{0:0000.0000}", 157.42); // 輸出 0157.4200
-
-
每3位數(千)加逗號
-
(String.Format("{0:0,0}", 38560); // 輸出 38,560
-
-
格式化電話號碼
-
(String.Format("{0:(###) ###-####}", 8005551212); // 輸出 (800) 555-1212
-
-
金額的表示
-
(String.Format("{0:$#,##0.00;($#,##0.00);Zero}", 0); // 這個會顯示 Zero
-
(String.Format("{0:$#,##0.00;($#,##0.00);Zero}", 1243.50); // 這個會顯示 $1,243.50
依照上面格式範例 ~ 套用到我的報表要呈現的欄位 ~ 如以下 ~
C#:
-
private void DataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
-
{
-
if (e.Item.ItemIndex.ToString() != "-1")
-
{
-
e.Item.Cells[0].Text = string.Format("{0:#,0.0}",double.Parse(e.Item.Cells[3].Text.ToString()));
-
}
-
}
參考資料來源:
http://blog.stevex.net/index.php/string-formatting-in-csharp/
本篇文章引用網址:
|
其他隨機文章: |



