您的位置:首页 > 编程语言 > Java开发

转 .Net/C#/VB/T-SQL/Java/Script 实现: 将天文数字转换成中文大写 (2000 年前的思路,打劫的,一点儿技术含量都没有)

2005-07-11 10:08 1236 查看
下面的是转贴

Microshaoft (大舌头)

的帖子,正好项目用上,想法还可以,但是不能区别小数点和最后不能添加上金额单位!

C# Code:

namespace Microshaoft
namespace Microshaoft

namespace Test

T-SQL UDF Code:

alter 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
set @k = len(@)/4

select @k = @k + 1
where @m > 0

declare @i integer
set @i = @k

while (@i > 0)
begin --outer
declare @L integer
set @L = 4

select @L = @m
where @i = @k and @m != 0

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)
select @num = 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
select @s = @s + @num
where @j < @ll - 1
and cast(substring(@ss,(@j+1)+1,1) as integer) > 0
and right(@ss,1) != @num
end
else
begin
declare @jj integer
set @jj = 1

select @jj = @j - 1
where @j > 1

select @s = @s + @num
where not (@n = 1
and @j = @ll - 2
and (len(@s) = 0
or right(@s,1) = '零'
)
)

select @s = @s + 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)
select @unit = 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
select @s = @s + @unit
where cast(@ss as integer) != 0
end
else
begin
set @s = @s + @unit
end
set @i = @i - 1 -- outer
end --out
return @s
end

VB6 Code:
《VB6 之数据格式化对象使用技巧》
http://search.csdn.net/Expert/topic/38/38970.xml?temp=.5078089
<<精华: 将金额小写转大写的代码可转到亿位>>
http://www.dev-club.com/club/bbs/showEssence.asp?id=20684&page=1

VB.Net Code:
可自行将 C# Code 编译成 EXE 后, Reflector 反编译获取 VB.Net/Delphi.Net/IL 等语言源码

Java Code:

public class Class1

JavaScript:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="playyuer㊣www.Microshaoft.com">
</HEAD>

<BODY>
</SCRIPT>
</BODY>
</HTML>

原文:http://www.cnblogs.com/microshaoft/archive/2005/04/02/131008.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐