注册 登录
编程论坛 ASP技术论坛

求解,人民币小写转大写的问题!

greatyollow 发布于 2007-10-05 11:49, 1651 次点击
运行后结果为:贰佰贰拾贰亿贰仟贰佰贰拾贰万贰仟贰佰贰拾贰元
(长度为11,小写为22222222222,也就是第二句中的那个数)
直接改这个数可以得到正解.

怎么改才行,请朋友们指教!

代码如下
<% if rs.eof Then
call Money(22222222222)
function Money(thenumber)
dim n,String1,String2,length
dim one(),onestr()
String1="零壹贰叁肆伍陆柒捌玖"
String2="万仟佰拾亿仟佰拾万仟佰拾元"
length=len(thenumber)
redim one(length-1)
redim onestr(length-1)
for n=0 to length-1
one(n)=mid(thenumber,n+1,1)
one(n)=mid(string1,one(n)+1,1)
onestr(n)=mid(string2,14-length+n,1)
one(n)=one(n)&onestr(n)
next
Money=replace(join(one)," ","")
Money=replace(Money,"零元","元")
Money=replace(Money,"零万","万")
Money=replace(Money,"零亿","亿")
Money=replace(Money,"零仟","零")
Money=replace(Money,"零佰","零")
Money=replace(Money,"零拾","零")
do while not instr(Money,"零零")=0
Money=replace(Money,"零零","零")
loop
end function
%>
16 回复
#2
月夜2007-10-05 11:58

好晕

#3
madpbpl2007-10-05 12:53
试试UCase函数,这个说的不对,只能对字母转换,数字不起作用,抱歉!

[此贴子已经被作者于2007-10-5 13:03:20编辑过]


#4
greatyollow2007-10-05 13:00
我是初学者,能不能说细一点!!
#5
greatyollow2007-10-05 13:07
我说的是123456元,转换为壹拾贰万叁仟肆佰伍拾陆元
#6
madpbpl2007-10-05 13:07
楼上参考一下这个贴子,和你说的基本上一致,而且有注释的
[url]http://www.im486.com/Article/NET/ASPJS/ASPJC/200509/1639.shtml?ArticleID=1639[/url]
#7
greatyollow2007-10-05 13:25
谢谢
#8
greatyollow2007-10-05 13:31
刚刚看过了:
两个问题:1、变量Money不能重新定义?2、运行结果问题同上。

仍然表示感谢,万分感谢!!
#9
greatyollow2007-10-05 13:41
#10
madpbpl2007-10-05 13:41

把dim那一行删掉
程序如下


<%call Money(333333333333)
function Money(thenumber)
//dim Money,i,String1,String2,length,checkp'定义变量
dim one(),onestr()'定义数组
String1 = "零壹贰叁肆伍陆柒捌玖"
String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分厘毫"
checkp=instr(thenumber,".")'判断是否含有小数位
if checkp<>0 then
thenumber=replace(thenumber,".","")'去除小数位
end if
length=len(thenumber) '取得数据长度
redim one(length-1)'重新定义数组大小
redim onestr(length-1)'重新定义数组大小
for i=0 to length-1
one(i)=mid(thenumber,i+1,1) '循环取得每一位的数字
one(i)=mid(string1,one(i)+1,1)'循环取得数字对应的大写
if checkp=0 then
'不含有小数的数据其数字对应的单位
onestr(i)=mid(string2,14-length+i,1)
else
'含有小数的数据其数字对应的单位
onestr(i)=mid(string2,15-length+i+len(thenumber)-checkp,1)
end if
one(i)=one(i)&onestr(i)'将数字与单位组合
next
Money=replace(join(one)," ","") '取得数组中所有的元素,并连接起来
Money=replace(Money,"零元","元")
Money=replace(Money,"零万","万")
Money=replace(Money,"零亿","亿")
Money=replace(Money,"零仟","零")
Money=replace(Money,"零佰","零")
Money=replace(Money,"零拾","零")
do while not instr(Money,"零零")=0
Money=replace(Money,"零零","零")
loop
response.write Money '显示结果
end function
%>
红色的是你要调用的,Money(333333333333),函数是Money,333333333333是参数,根据实际情况调整就可以了。

[此贴子已经被作者于2007-10-5 13:46:15编辑过]

#11
greatyollow2007-10-05 14:22
#12
greatyollow2007-10-05 14:28
我前面求和:thenumber=230

是不是下面接着运行就行了
???
#13
greatyollow2007-10-05 14:30
你说的这一句,我一点都不明白,请再详细一点好不好:

红色的是你要调用的,Money(333333333333),函数是Money,333333333333是参数,根据实际情况调整就可以了。
#14
greatyollow2007-10-05 14:40
我把两个问题都放到一个贴子上了,请看:

《关于分页显示后的求和、小写转大写问题!!》
#15
一陀屎2007-10-05 15:49
只有本站会员才能查看附件,请 登录


看了你的题后,用了一个函数,两个过程才写出来

#16
wcwtitxu2007-10-06 05:51
[CODE]

<%
Function Money(thenumber)
Dim n, String1, String2, length, theDecimal, theInteger
Dim one(), onestr()
String1 = "零壹贰叁肆伍陆柒捌玖"
String2 = "万仟佰拾亿仟佰拾万仟佰拾元"
theInteger = Int(thenumber)
theDecimal = thenumber - theInteger
length = Len(theInteger)
Redim one(length-1)
Redim onestr(length-1)
For n=0 To length-1
one(n) = Mid(theInteger, n+1, 1)
one(n) = Mid(String1, one(n)+1, 1)
onestr(n) = Mid(String2, 14-length+n, 1)
one(n) = one(n) & onestr(n)
Next
Money = Replace(join(one), " ", "")
Money = Replace(Money, "零元", "元")
Money = Replace(Money, "零万", "万")
Money = Replace(Money, "零亿", "亿")
Money = Replace(Money, "零仟", "零")
Money = Replace(Money, "零佰", "零")
Money = Replace(Money, "零拾", "零")
Do While Not instr(Money, "零零") = 0
Money = Replace(Money, "零零", "零")
Loop
If theDecimal<>0 Then
theDecimal = theDecimal * 10
Money = Money & Mid(String1, Int(theDecimal)+1, 1) & "角"
theDecimal = theDecimal - Int(theDecimal)
End If
If theDecimal<>0 Then
theDecimal = theDecimal * 10
Money = Money & Mid(String1, CInt(theDecimal)+1, 1) & "分"
End If
End Function
Response.Write Money(2452835627822.26)
%>

[/CODE]

[此贴子已经被作者于2007-10-6 5:52:56编辑过]

#17
greatyollow2007-10-12 09:12
非常感谢,已经解决好了.谢谢大家提供了这么好的思路,也感谢大家的指点.
1