日期:2014-05-18  浏览次数:20463 次

在sql中,如何将查询到的字段进行四舍五入后显示出来
在sql中,如何将查询到的字段进行四舍五入后显示出来
比如:
select Price from F --Price是nvarchar(50)类型的 Price的值和123243.2324类似
求解:如何通过四舍五入后保留两位小数???

------解决方案--------------------
SQL code

declare @F table (Price numeric(10,4))
insert into @F
select 123243.2324 union all
select 3243.2354 union all
select 22.2344

select CAST(Price AS DECIMAL(18,2)) AS Price from @F

/*
Price
---------------------------------------
123243.23
3243.24
22.23
*/