問題:要在Datagrid中顯示時間為2.08小時,我在SQL中這樣處理:SELECT 125 / 60.00 AS float
但在Datagrid中顯示為2.083333,請問如何寫代碼只保留兩位小數點2.08?
________________________________________________________________
答1:
float(7,2)
2表示保留兩位小數
________________________________________________________________
答2:
float(8,2)?在哪寫呢?
________________________________________________________________
答3:
在datagrid的屬性生成器中,列,數據格式設置表達式加上:
{0:f2}
________________________________________________________________
答4:
1.在sql語句中:select convert(dt,numeric(5,2)) from
2.在datagrid的綁定列的數據格式一欄添加:{0:f2}
________________________________________________________________
答5:
任選其一
________________________________________________________________
答6:
是這樣寫嗎“select convert(125/60.00,numeric(5,2)) from ”?
這樣寫運行時出錯啦...
________________________________________________________________
答7:
select round(125/60.00,2)
________________________________________________________________
答8:
select cast(125/60.00 as numeric(5,2))
________________________________________________________________
答9:
Thank you.
請問使用round和cast有何區別?
________________________________________________________________
答10:
把數據庫中的相應字段設置為decimal,然後把他的小數位改成2
________________________________________________________________
答11:
在Datagrid的OnItemDataBound事件中寫e.item.cell[0].text = float(7,2).Tostring()
就在dg中第0列中轉換並顯示出來了
________________________________________________________________
答12:
方法確定很多
1、設計字段時類型為numeric,小數位設置成2
2、在sql語句中轉換:select convert(字段,numeric(18,2)) AS 字段Ex from 表
如果是datagrid綁定列<Columns>,則<asp:BoundColumn DataField="字段Ex " />
3、在datagrid的綁定列的屬性中這樣使用
<asp:BoundColumn DataField="字段" DataFormatString ="{0:f2}" />