问题:要在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}" />