如何将十进制值转换为逗号?
this帮助我.但我的问题小数位只设置为2 ..我希望小数为2,3或4 ..示例
1,234.123 or 1,234.12345
我试过了
convert(varchar,convert(decimal(18,4),1234.1234567),1)
产量:1234.1234
没有逗号.但如果我用钱,小数只是2
convert(varchar,convert(money,1)
Output : 1,234.12
解决方法
不考虑这是个好主意……
select dbo.F_AddThousandSeparators(convert(varchar,1))
-- Author: bummi -- Create date: 20121106 CREATE FUNCTION F_AddThousandSeparators(@NumStr varchar(50)) RETURNS Varchar(50) AS BEGIN declare @OutStr varchar(50) declare @i int declare @run int Select @i=CHARINDEX('.',@NumStr) if @i=0 begin set @i=LEN(@NumStr) Set @Outstr='' end else begin Set @Outstr=SUBSTRING(@NUmStr,@i,50) Set @i=@i -1 end Set @run=0 While @i>0 begin if @Run=3 begin Set @Outstr=','+@Outstr Set @run=0 end Set @Outstr=SUBSTRING(@NumStr,1) +@Outstr Set @i=@i-1 Set @run=@run + 1 end RETURN @OutStr END GO