本文主要是介绍将数字转换为汉语简体中文,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
DECLARE @Str nVARCHAR(100),@Strs nVARCHAR(100),
@Strss nVARCHAR(100),
@I int,
@j INT,
@leng INT,
@z int,
@xiaoshu varchar(50)
/*Define @str To Save Chinese*/
SELECT @Str=N'十百千万十百千亿'
SELECT @Strs=N'零一二三四五六七八九十'
SET @Strss=''
SET @i=300202051
set @xiaoshu='300202051.239089'
set @z=charindex('.',@xiaoshu)
if(charindex('.',convert(nvarchar(100),@xiaoshu)))>0
set @xiaoshu=substring(@xiaoshu,@z+1,len(@xiaoshu)-@z)
WHILE(LEN(@i)>1)
BEGIN
SET @leng=LEN(@I)
SET @j=@i/POWER(10,LEN(@i)-1)
SET @i=@i%POWER(10,LEN(@i)-1)
IF(@leng-len(@I)>1 )
BEGIN
if(@leng>4 and len(@i)<5 and @leng<10)
begin
SET @Strss=@Strss+SUBSTRING(@Strs,@j+1,1)+SUBSTRING(@Str,@leng-1,1)+N'万'
SET @Strss=@Strss+N'零'
end
else
begin
SET @Strss=@Strss+SUBSTRING(@Strs,@j+1,1)+SUBSTRING(@Str,@leng-1,1)
SET @Strss=@Strss+N'零'
end
END
ELSE
SET @Strss=@Strss+SUBSTRING(@Strs,@j+1,1)+SUBSTRING(@Str,LEN(@i),1)
END
IF(@I<>0)
SET @Strss=@Strss+SUBSTRING(@Strs,cast(@i as int)+1,1)
if(len(@xiaoshu)>0)
begin
set @Strss=@Strss+N'点'
set @i=convert(int,@xiaoshu)
if(substring(@xiaoshu,1,1)='0')
set @Strss=@Strss+N'零'
While(len(@i)<>1)
begin
SET @leng=LEN(@I)
SET @j=@i/POWER(10,LEN(@i)-1)
SET @i=@i%POWER(10,LEN(@i)-1)
IF(@leng-len(@I)>1)
BEGIN
SET @Strss=@Strss+SUBSTRING(@Strs,@j+1,1)
SET @Strss=@Strss+N'零'
END
ELSE
begin
SET @Strss=@Strss+SUBSTRING(@Strs,@j+1,1)
end
end
end
IF(@I<>0 and @xiaoshu<>'')
SET @Strss=@Strss+SUBSTRING(@Strs,cast(@i as int)+1,1)
print @Strss
这篇关于将数字转换为汉语简体中文的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!