How to get only two numbers after decimal

I have money field in sql table, when I fetch record from table and bind to datagrid it shows money and also 100.0000 four characters from decimal, I only need two. Plz suggests.

+2


a source to share


5 answers


Try the following:

SELECT
    ROUND(YourColumn,2)
    FROM ...

      

Check it:



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


a source


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

The example below uses ASP.NET DataGrid. In the column, you need to specify the DataFormatString property on the column. {0: C2} in this case displays the property as a currency with two 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>

      

+3


a source


select cast(round(123.4321,2) as decimal(18,2))

      

is also the solution to your problem.

+2


a source


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

0


a source


Check out GridView Samples for ASP.NET 2.0: Formatting a GridView .

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

0


a source







All Articles