Manoj Wadhwani
Manoj Wadhwani

Reputation: 1547

how to get only two number after decimal

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.

Upvotes: 2

Views: 22719

Answers (5)

kbvishnu
kbvishnu

Reputation: 15630

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

is also a solution for your problem.

Upvotes: 2

Wallace Breza
Wallace Breza

Reputation: 4948

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>

Upvotes: 3

kervin
kervin

Reputation: 11858

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

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

Upvotes: 0

KM.
KM.

Reputation: 103597

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)

Upvotes: 0

Philip Kelley
Philip Kelley

Reputation: 40319

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.

Upvotes: 0

Related Questions