比如:
select Price from F --Price是nvarchar(50)类型的 Price的值和123243.2324类似
求解:如何通过四舍五入后保留两位小数???
3 个解决方案
#1
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
*/
#2
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
*/
#3
谢谢,问题已经解决了。你给的有点复杂,具体解决方法:
select convert(decimal(18,2),round(convert(decimal,Price)/10000,50)) as Price from F
select convert(decimal(18,2),round(convert(decimal,Price)/10000,50)) as Price from F
#1
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
*/
#2
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
*/
#3
谢谢,问题已经解决了。你给的有点复杂,具体解决方法:
select convert(decimal(18,2),round(convert(decimal,Price)/10000,50)) as Price from F
select convert(decimal(18,2),round(convert(decimal,Price)/10000,50)) as Price from F