I have table which has a column of float
data type in SQL Server
I want to return my float
datatype column value with 2 decimal places.
for ex: if i insert 12.3
,it should return 12.30
if i insert 12
,it should return 12.00
This question is related to
sql-server
sql-server-2008
sqldatatypes
You can also Make use of the Following if you want to Cast and Round as well. That may help you or someone else.
SELECT CAST(ROUND(Column_Name, 2) AS DECIMAL(10,2), Name FROM Table_Name
want to convert the column name Amount as float number with 2 decimals
CASE WHEN EXISTS (SELECT Amount From InvoiceFee Ifee WHERE IFEE.InvoiceId =
DIR.InvoiceId AND FeeId = 'Freight Cost')
THEN CAST ((SELECT Amount From InvoiceFee Ifee WHERE IFEE.InvoiceId =
DIR.InvoiceId AND FeeId = 'Freight Cost') AS VARCHAR)
ELSE '' END AS FCost,
You can also do something much shorter:
SELECT FORMAT(2.3332232,'N2')
You can also use below code which helps me:
select convert(numeric(10,2), column_name) as Total from TABLE_NAME
where Total
is alias of the field you want.
Source: Stackoverflow.com