How to get only two numbers after decimal
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 to share
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 to share
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 to share