ASP的貨幣書寫怎樣轉換成英文

brinkboy 2002-05-06 02:14:59
各位高手我有個問題想請教大家
如何將貨幣轉換成英文的輸入寫形式
如:83.20 為: EIGHTY-TREE AND CENTS TWENTY ONLY
...全文
31 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
micher_yan 2002-05-06
不能给你现成的例子,不过你可以参考以下以下数字转换中文大写的情况:
'将传入的数字转换成中文大写,并通过函数返回,不是通过response.write返回的
'num是传入的数字型参数
'传入的数不能大于99999,9999,9999.99,否则将得不到正确结果!!!!!
'功能表示13位数字
function y_big_write(num)
'需要调用以下两个自定义函数y_big_num,y_big_Unit
dim i
dim num_str
dim big_num,small_num
dim num_for
dim outputnum,outputnum1
outputnum=""
num_str=cstr(formatnumber(num,2,true,false,false))
big_num=left(num_str,len(num_str)-3)
small_num=right(num_str,2)
if len(big_num)>13 then
response.write "所需要转换成人民币大写的数字超出系统运算范围,系统运算非正常退出....."
response.end
end if
for i=1 to len(big_num)
num_for=right(left(big_num,len(big_num)-i+1),1)
'outputnum=y_big_num(num_for)&y_big_Unit(i)&outputnum
if y_big_num(num_for)="零" and (y_big_Unit(i)="元" or y_big_Unit(i)="万" or y_big_Unit(i)="亿") then '是标志位
outputnum=y_big_Unit(i)&outputnum
elseif y_big_num(num_for)="零" and (y_big_Unit(i)<>"元" and y_big_Unit(i)<>"万" and y_big_Unit(i)<>"亿") then '不是标志位
outputnum=y_big_num(num_for)&outputnum
else '其他情况
outputnum=y_big_num(num_for)&y_big_Unit(i)&outputnum
end if
next
'将连续的零替换成一个“零”
outputnum=replace(outputnum,"零零零零","零")
outputnum=replace(outputnum,"零零零","零")
outputnum=replace(outputnum,"零零","零")
'注意替换的先后顺序,换掉标志位前的零
outputnum=replace(outputnum,"零元","元")
outputnum=replace(outputnum,"零万","万")
outputnum=replace(outputnum,"零亿","亿")
'换掉大单位到小单位造成的误差,因为只可能出现万亿,而不可能出现亿万
outputnum=replace(outputnum,"亿万","亿")
'重新考虑整数为零的情况
if big_num="0" then
outputnum="" '将整数位设置成空
end if
'处理小数
outputnum1=""
if left(small_num,1)<>"0" then
outputnum1=y_big_num(left(small_num,1))&"角"
else
if big_num="0" then
outputnum1=""
else
outputnum1="零"
end if
end if
if right(small_num,1)<>"0" then
outputnum1=outputnum1&y_big_num(right(small_num,1))&"分"
end if
if small_num="00" then
outputnum1=""
end if
y_big_write=outputnum&outputnum1&"整"
if num_str="0.00" then
y_big_write="零元整"
end if
end function
'response.write y_big_write(100001.01)

'把传入的数字字符转换成大写,通过函数返回
'以下程序段已经通过测试
function y_big_num(strT)
select case strT
case "1"
y_big_num="壹"
case "2"
y_big_num="贰"
case "3"
y_big_num="叁"
case "4"
y_big_num="肆"
case "5"
y_big_num="伍"
case "6"
y_big_num="陆"
case "7"
y_big_num="柒"
case "8"
y_big_num="捌"
case "9"
y_big_num="玖"
case "0"
y_big_num="零"
end select
end function
function y_big_Unit(i)
select case i
case 1
y_big_Unit="元"
case 2
y_big_Unit="拾"
case 3
y_big_Unit="佰"
case 4
y_big_Unit="仟"
case 5
y_big_Unit="万"
case 6
y_big_Unit="拾"
case 7
y_big_Unit="佰"
case 8
y_big_Unit="仟"
case 9
y_big_Unit="亿"
case 10
y_big_Unit="拾"
case 11
y_big_Unit="佰"
case 12
y_big_Unit="仟"
case 13
y_big_Unit="万"
end select
end function
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2002-05-06 02:14
社区公告
暂无公告