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

brinkboy 2002-05-06 02:14:59
各位高手我有個問題想請教大家
如何將貨幣轉換成英文的輸入寫形式
如:83.20 為: EIGHTY-TREE AND CENTS TWENTY ONLY
...全文
67 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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