How to display two digits after decimal point in SQL Server

后端 未结 4 1374
生来不讨喜
生来不讨喜 2020-12-23 09:27

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

相关标签:
4条回答
  • 2020-12-23 09:41

    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
    
    0 讨论(0)
  • 2020-12-23 09:43
    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

    0 讨论(0)
  • 2020-12-23 09:53

    You can also do something much shorter:

    SELECT FORMAT(2.3332232,'N2')

    0 讨论(0)
  • 2020-12-23 09:56

    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.

    0 讨论(0)
提交回复
热议问题