22,210
社区成员
发帖
与我相关
我的任务
分享
declare @T table(Num float(38))--float\real轉換為字符
insert @T select 1230
union all select 1234
union all select 123.45
union all select 123.456
union all select 123.4567
union all select 123.45678
select *,rtrim(Num) as [直接轉換為字符] from @T
select
Num=case when len(Num)=charindex('.',Num) then stuff(Num,len(Num),1,'') else Num end
from
(
select
Num=left(Num,Len(Num)-patindex('%[^0]%',reverse(Num))+1)
from (
select rtrim(cast(Num as decimal(38,10))) as Num from @T
)T
)T2
declare @f float(34)
set @f=12345.55
select rtrim(@f) as 轉換的值,@f as 值
轉換的值 值
----------------------- ----------------------
12345.5 12345.55
(1 個資料列受到影響)
select right('00000000000'+cast(12345.55 as varchar(20)),11)
select right('0000'+rtrim(cast(12345.55 as numeric(10,2))),11)
select '00000000000'+ltrim(12345.55)
select right('0000'+cast(12345.55 as varchar) ,11)
/*
----------------------
00012345.55
(所影响的行数为 1 行)
*/