tags:

views:

79

answers:

4

i have money field in sql table when i m extracting record by table and binding it to datagrid it show money as well 100.0000 four character from decimal i need only two . Plz suggest.

A: 

If you are returning the data in numeric format, and you should (as opposed to converting it to a string), then this is an application presentation/formatting issue.

Philip Kelley
+1  A: 

Try this:

SELECT
    ROUND(YourColumn,2)
    FROM ...

Test it out:

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)
KM
A: 

Check out GridView Examples for ASP.NET 2.0: Formatting the GridView.

You need to set the DataFormatString property to eg. "{0:0.00}"

kervin
+3  A: 

In my opinion this formatting should be done on the UI side.

The below example shown uses an ASP.NET DataGrid. Within the column you need to specify the DataFormatString property on the column. The {0:C2} in this case displays the property as a currency with 2 decimal places


<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>
Wallace Breza