怎样format数字型成百分比?
在sql文里怎样把类似
"0.015555 "
字段检索出来转化成
"1.56% "
(百分比小数点后2位)
[解决办法]
declare @v decimal(18,6)
set @v=0.015555
select @v
--转换为 "1.56% "格式的SQL语句
select cast(cast(@v*100 as decimal(18,2)) as varchar(20)) + '% '
/*
返回:
1.56%
*/
[解决办法]
printf
[解决办法]
declare @v decimal(18,6)
set @v=0.015555
------------------------------
select cast(cast(round(@v*100,2) as decimal(18,2)) as varchar(20)) + '% '
or
select convert(varchar(20),convert(decimal(16,2),round(@v*100,2)))+ '% '