2010-05-12 74 views

回答

0

试试这个:

SELECT 
    ROUND(YourColumn,2) 
    FROM ... 

测试出来:

DECLARE @YourTable table (RowValue money) 
INSERT @YourTable VALUES (123.4321) 
INSERT @YourTable VALUES (0.001) 
INSERT @YourTable VALUES (1.1251) 

SELECT 
    RowValue, ROUND(RowValue,2) AS TwoPlaces 
    FROM @YourTable 

OUTPUT:

RowValue    TwoPlaces 
--------------------- --------------------- 
123.4321    123.43 
0.001     0.00 
1.1251    1.13 

(3 row(s) affected) 
0

如果您要以数字格式返回数据,并且您应该(而不是将其转换为字符串),那么这是一个应用程序演示/格式问题。

3

在我看来,这种格式应该在UI端完成。

下面的示例使用ASP.NET DataGrid。在列中,您需要指定列上的DataFormatString属性。该{0:C2}在这种情况下显示属性为货币与2位小数


<asp:DataGrid ID="grid1" AutoGenerateColumns="false" runat="server"> 
    <Columns> 
     <asp:BoundColumn HeaderText="Product Name" DataField="Name" /> 
     <asp:BoundColumn HeaderText="Price" DataField="Price" DataFormatString="{0:C2}" /> 
    </Columns> 
</asp:DataGrid> 
2
select cast(round(123.4321,2) as decimal(18,2)) 

也是你的问题的解决方案。

相关问题