How to display two digits after decimal point in SQL Server

Sql ServerSql Server-2008Sqldatatypes

Sql Server Problem Overview


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

Sql Server Solutions


Solution 1 - Sql Server

select cast(your_float_column as decimal(10,2))
from your_table

decimal(10,2) means you can have a decimal number with a maximal total precision of 10 digits. 2 of them after the decimal point and 8 before.
The biggest possible number would be 99999999.99

Solution 2 - Sql Server

You can also do something much shorter:

SELECT FORMAT(2.3332232,'N2')

Solution 3 - Sql Server

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.

Solution 4 - Sql Server

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

Solution 5 - Sql Server

select cast(56.66823 as decimal(10,2))

This returns 56.67.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSantoshView Question on Stackoverflow
Solution 1 - Sql Serverjuergen dView Answer on Stackoverflow
Solution 2 - Sql ServerShiroyView Answer on Stackoverflow
Solution 3 - Sql ServerBha15View Answer on Stackoverflow
Solution 4 - Sql ServerPatsonLeanerView Answer on Stackoverflow
Solution 5 - Sql ServerKaliView Answer on Stackoverflow