T-SQL/.Net/C#/VB/Java 实现: 将天文数字转换成中文大写

playyuer 2005-04-03 03:35:49
思路参阅:
http://www.cnblogs.com/Microshaoft/archive/2005/04/02/131008.html

create function ConvertNumberToChinese(@ varchar(100))
returns varchar(100)
as
begin
--declare @ varchar(100)
--set @ = '101140101031013'
declare @s varchar(100)
set @s = ''
declare @p integer
set @p = 0
declare @m integer
set @m = len(@) % 4
declare @k integer
if @m > 0
begin
set @k = len(@)/4 + 1
end
else
begin
set @k = len(@)/4
end
declare @i integer
set @i = @k
while (@i > 0)
begin --out
declare @L integer
set @L = 4
if @i = @k and @m != 0
begin
set @L = @m
end
declare @ss varchar(4)
set @ss = substring(@,@p+1,@L)
declare @ll integer
set @ll = len(@ss)
--inner
declare @j integer
set @j = 0
while (@j < @ll) --inner
begin --inner
declare @n integer
set @n = cast(substring(@ss,@j+1,1) as integer)
declare @num varchar(2)
set @num =( select Num
from
(
select 0 as id,'零' as Num
union all select 1,'壹'
union all select 2,'贰'
union all select 3,'叁'
union all select 4,'肆'
union all select 5,'伍'
union all select 6,'陆'
union all select 7,'柒'
union all select 8,'捌'
union all select 9,'玖'
) Nums
where id = @n
)
if @n = 0
begin
if @j < @ll - 1
and cast(substring(@ss,(@j+1)+1,1) as integer) > 0
and right(@ss,1) != @num
begin
set @s = @s + @num
end
end
else
begin
set @s = @s + @num + ( select digit
from
(
select 0 as id,'' as digit
union all select 1,'拾'
union all select 2,'佰'
union all select 3,'仟'
) digits
where id = @ll - @j - 1
)
end
set @j = @j + 1 --inner
end --inner
set @p = @p + @L

declare @unit varchar(10)
set @unit = ( select Unit
from
(
select 0 as id,'' as Unit
union all select 1,'[万]'
union all select 2,'[亿]'
union all select 3,'[万亿]'
) Units
where id = @i - 1
)
if @i < @k
begin
if cast(@ss as integer) != 0
begin
set @s = @s + @unit
end
end
else
begin
set @s = @s + @unit
end
set @i = @i - 1 -- out
end --out
return @s
/*
--Test:
select dbo.ConvertNumberToChinese('40000000000')
,dbo.ConvertNumberToChinese('40000000001')
,dbo.ConvertNumberToChinese('400000010000')
,dbo.ConvertNumberToChinese('40101031013')
,dbo.ConvertNumberToChinese('101140101031013')
,dbo.ConvertNumberToChinese('100000001000003')
,dbo.ConvertNumberToChinese('10011003')
,dbo.ConvertNumberToChinese('10010103')
,dbo.ConvertNumberToChinese('10010013')
*/
end
...全文
250 24 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andy__Huang 2005-06-04
  • 打赏
  • 举报
回复
up
telcom 2005-06-04
  • 打赏
  • 举报
回复
如何把小数点后面的也转换成角分
silentwins 2005-06-04
  • 打赏
  • 举报
回复
这个太强了!
淡蓝冰 2005-06-04
  • 打赏
  • 举报
回复
學習
PARAMETERS lnMoney
lnNumber = lnMoney
ChinaMoney = ""
DIME ChinaNo(10)
ChinaNo(1) = "錨"
ChinaNo(2) = "瓞"
ChinaNo(3) = "楚"
ChinaNo(4) = ""
ChinaNo(5) = "佹"
ChinaNo(6) = "斪"
ChinaNo(7) = "翻"
ChinaNo(8) = ""
ChinaNo(9) = "副"
ChinaNo(10) = "墾"
DIME Cdw(2)
Cdw(1)="褒"
Cdw(2)="煦"
DIME ChinaNum(10)
ChinaNum(1) = "啋"
ChinaNum(2) = "夆"
ChinaNum(3) = "唱"
ChinaNum(4) = ""
ChinaNum(5) = "勀"
ChinaNum(6) = "夆"
ChinaNum(7) = "唱"
ChinaNum(8) = ""
ChinaNum(9) = "砬"
ChinaNum(10) = "夆"
lnIntNumber = INT(lnNumber)
lcIntNumber = ALLTRIM(STR(lnIntNumber,10,0))
lnDicNumber = Int((lnNumber-lnIntNumber)*100)
lcDicNumber = IIF(!EMPTY(lnDicNumber),STR(lnDicNumber,2,0),"")

N = 1
FOR I = LEN(lcIntNumber) TO 1 STEP -1
FOR J = 1 TO 10
IF VAL(SUBST(lcIntNumber,I,1)) = J-1
ChinaMoney = ChinaNo(J)+ChinaNum(N)+ChinaMoney
N = N+1
EXIT
ENDIF
ENDFOR
ENDFOR
IF !EMPTY(lcDicNumber)
FOR Z = 1 TO 2
FOR P = 1 TO 10
IF VAL(SUBST(lcDicNumber,Z,1)) = P-1
ChinaMoney = ChinaMoney+ChinaNo(P)+Cdw(Z)
EXIT
ENDIF
ENDFOR
ENDFOR
ELSE
ChinaMoney=ChinaMoney+"淕"
ENDIF
RETURN ChinaMoney
wangshidu 2005-06-04
  • 打赏
  • 举报
回复
极力支持
收藏
学习
brando_beat 2005-06-04
  • 打赏
  • 举报
回复
我顶顶顶!!!
牛人太多了!!
赶紧收藏!!!
Alden 2005-05-27
  • 打赏
  • 举报
回复
太牛了
子陌红尘 2005-04-05
  • 打赏
  • 举报
回复
大强!
TigerSuper 2005-04-04
  • 打赏
  • 举报
回复
UP
zzroom 2005-04-04
  • 打赏
  • 举报
回复
受教了!
多谢!
郭大侠_ 2005-04-03
  • 打赏
  • 举报
回复
我顶顶顶!!!
牛人太多了!!
赶紧收藏!!!
poonzsp 2005-04-03
  • 打赏
  • 举报
回复
干部来了·好好听课学东西
U2U2U2U2 2005-04-03
  • 打赏
  • 举报
回复
不错,收藏
但是现在用的不是很多
现在基本上可以使用开发软件解决问题
点点星灯 2005-04-03
  • 打赏
  • 举报
回复
好厉害啊,要多多的学习啊!!
yunshiyu 2005-04-03
  • 打赏
  • 举报
回复
妈呀!哈哈
chiwei 2005-04-03
  • 打赏
  • 举报
回复
厉害,星星以上是什么了?
playyuer 2005-04-03
  • 打赏
  • 举报
回复
不会是小强的意思吧?
_谁啊 2005-04-03
  • 打赏
  • 举报
回复
厉害啊!!!
tmxkdldw 2005-04-03
  • 打赏
  • 举报
回复
好厉害啊,要多多的学习啊!!
631799 2005-04-03
  • 打赏
  • 举报
回复
强兄啊......
加载更多回复(4)

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧