Gridview中的舍入十进制

时间:2013-11-30 01:11:00

标签: asp.net sql sql-server

我正在尝试将代码的结果舍入到2位小数,但ROUND不起作用。有帮助吗?谢谢!

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
     SelectCommand="SELECT [Id], [attempts], [total], (round(attempts / total,(2))) AS [Percentage] FROM [Game]">
</asp:SqlDataSource>

2 个答案:

答案 0 :(得分:0)

我打赌你可以使用

CAST(ROUND(attempts/total,2) as DECIMAL(12,2))

OR

attempts/CAST(total as DECIMAL(12,2))

OR

CAST(attempts AS DECIMAL(12,2))/total

答案 1 :(得分:0)

试试这个       “              SelectCommand =“SELECT [Id],[attempts],[total],round((attempts / total),2)AS [Percentage] FROM [Game]”&gt;         

更新:

你试过了吗?

SELECT Cast( 2.555 as decimal(53,2))

这将返回2.55。这就是你想要的吗?