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.
我有一个表,它在SQL Server中有一个浮点数据类型的列,我想要将浮点数据类型的列值返回2位小数。
for ex: if i insert 12.3
,it should return 12.30
对于例:如果我插入12.3,它应该返回12.30
if i insert 12
,it should return 12.00
如果我插入12,它应该返回12。00
2 个解决方案
#1
78
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.
十进制(10,2)意味着您可以有一个十进制数,其最大总精度为10位。其中2个是小数点后8位。
#2
2
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.
其中Total是所需字段的别名。
#1
78
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.
十进制(10,2)意味着您可以有一个十进制数,其最大总精度为10位。其中2个是小数点后8位。
#2
2
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.
其中Total是所需字段的别名。