加入收藏 | 设为首页 | 会员中心 | 我要投稿 衡阳站长网 (https://www.0734zz.cn/)- 数据集成、设备管理、备份、数据加密、智能搜索!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

ASP将数字转中文数字 大写金额 的函数

发布时间:2021-12-13 22:48:40 所属栏目:Asp教程 来源:互联网
导读:项目中遇到想将阿拉伯金额数字转为中文汉字数字形式,下面脚本之家小编就为大家分享一下ASP将数字转中文数字的函数的实现方法,需要的朋友可以参考下 下面跟大家分享2种不同函数的实现方式。 ASP将数字转中文数字金额的函数一 % function Money(thenumber) dim
项目中遇到想将阿拉伯金额数字转为中文汉字数字形式,下面脚本之家小编就为大家分享一下ASP将数字转中文数字的函数的实现方法,需要的朋友可以参考下
 
 
下面跟大家分享2种不同函数的实现方式。
 
ASP将数字转中文数字金额的函数一
 
<%
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
Response.write Money(8200001)
%>
ASP阿拉伯数字转中文数字
 
<%
'################################
'函数名:阿拉伯数字转中文数字函数
'################################
function chnumstr(num)
num=int(abs(num))
strlen=len(num)
for i=1 to strlen
select case mid(num,i,1)
case 1:chnum="一":case 2:chnum="二":case 3:chnum="三"
case 4:chnum="四":case 5:chnum="五"
case 6:chnum="六":case 7:chnum="七":case 8:chnum="八"
case 9:chnum="九":case 0:chnum="零"
end select
chnumstr=chnumstr&chnum
if i=strlen-1 and mid(num,i,1)<>0 then chnumstr=chnumstr&"十"
if i=strlen-2 and mid(num,i,1)<>0 then chnumstr=chnumstr&"百"
if i=strlen-3 and mid(num,i,1)<>0 then chnumstr=chnumstr&"千"
if i=strlen-4 and mid(num,i,1)<>0 then chnumstr=chnumstr&"万"
if i=strlen-5 and mid(num,i,1)<>0 then chnumstr=chnumstr&"十"
if i=strlen-6 and mid(num,i,1)<>0 then chnumstr=chnumstr&"百"
if i=strlen-7 and mid(num,i,1)<>0 then chnumstr=chnumstr&"千"
if i=strlen-8 and mid(num,i,1)<>0 then chnumstr=chnumstr&"万"
next
if left(chnumstr,1)="一" then chnumstr=right(chnumstr,len(chnumstr)-1)
if right(chnumstr,1)="零" then chnumstr=left(chnumstr,len(chnumstr)-1)
end function
Response.write chnumstr("84221213")
%>
 

(编辑:衡阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读