四舍五入加千分位 create function GetFormatString(@dec decimal(28,8), @n int) returns varchar(32) as begin declare @str varchar(32), @len int, @left varchar(32), @right varchar(32),@end varchar(32) if @n!='0' BEGIN set @str= round(@dec,@n) select @left=left(@str,charindex('.',@str)-1),@len=len(@left)-2 while @len>1 begin select @left=stuff(@left,@len,0,','), @len=@len-3 end select @right=left(stuff(@str,1,charindex('.',@str),''), @n),@len=4 while @len <=len(@right) begin select @right=stuff(@right,@len,0,','), @len=@len 4 end set @end= @left '.' @right end else BEGIN set @str= round(@dec,@n) select @left=left(@str,charindex('.',@str)-1),@len=len(@left)-2 while @len>1 begin select @left=stuff(@left,@len,0,','), @len=@len-3 end select @right=left(stuff(@str,1,charindex('.',@str),''), @n),@len=4 while @len <=len(@right) begin select @right=stuff(@right,@len,0,','), @len=@len 4 end set @end= @left end return @end end select dbo.GetFormatString(123645.7889, 2) '±' 'MON' union all select dbo.GetFormatString(123645.7889, 3) '±' 'MON' union all select dbo.GetFormatString(123645.7889, 4) '±' 'MON'