新写了一个转中文大写金额的ASP函数

'格式化中文金额的方法
'@ prmtType 为"A" 时表示返回带零的全字串,否则返回中文习惯的金额
'调用方法:FormatChineseMoney(30503.34,"")

Function FormatChineseMoney(prmtMoney,prmtType)
 dim strMoney,strMoneyLeft,strMoneyRight
 if IsNumeric(prmtMoney) then
  strMoney=FormatCurrency(prmtMoney,2,-1,0,0)
  dim regMoney
  Set regMoney = New RegExp   ' 创建正则表达式。
  regMoney.Pattern = "^[¥|\$]?[+|-]?(\d+)?(?:\.(\d{1,2}))?$"   ' 设置模式。
  regMoney.IgnoreCase = True   ' 设置是否区分大小写。
  regMoney.Global = True   ' 设置全程匹配。
  if regMoney.test(strMoney) then
   Set oMatches = regMoney.Execute(strMoney)
   Set oMatch = oMatches(0)
   strMoneyLeft=oMatch.SubMatches(0)
   strMoneyRight=oMatch.SubMatches(1)
   FormatChineseMoney=ReplaceMoneyLeft(oMatch.SubMatches(0),prmtType)&ReplaceMoneyRight(oMatch.SubMatches(1),prmtType)&"整"
  else
   FormatChineseMoney="所传金钱金额不合规则!"
  end if
 else
  FormatChineseMoney="所传金钱金额不是数字!"
 end if
end Function

Function ReplaceMoneyLeft(prmtMoney,prmtType)
 dim intLenMoney,aryK,aryW,aryN,intModI,sNum,sNumA,i
 intLenMoney=Len(prmtMoney)
 aryK=Array("","拾","佰","仟")
 aryW=Array("","元","万","亿")
 aryN=Array("零","壹","贰","叄","肆","伍","陆","柒","捌","玖")
 for i=1 to intLenMoney
  sNum=aryN(Mid(prmtMoney,intLenMoney-i+1,1))&aryK((i-1) Mod 4)&aryW(GetWYIndex(i))&sNum
  sNumA="<span class=""spanCNMoneyMoney""> "&aryN(Mid(prmtMoney,intLenMoney-i+1,1))&" </span>"&"<span class=""spanCNMoneyUnit""> "&aryK((i-1) Mod 4)&aryW(GetWYIndex(i))&" </span>"&sNumA
 next
 if prmtType="A" then
  ReplaceMoneyLeft=sNumA
 else
  ReplaceMoneyLeft=ReplaceCNZeroLeft(sNum)
 end if
End Function

Function ReplaceMoneyRight(prmtMoney,prmtType)
 dim intLenMoney,aryF,aryN,intModI,sNum,sNumA,i
 intLenMoney=Len(prmtMoney)
 aryF=Array("","角","分")
 aryN=Array("零","壹","贰","叄","肆","伍","陆","柒","捌","玖")
 for i=intLenMoney to 1 step -1
  sNum=aryN(Mid(prmtMoney,i,1))&aryF(i)&sNum
  'response.Write(i&prmtMoney&Mid(prmtMoney,i,1)&aryN(Mid(prmtMoney,i,1)))
  sNumA="<span class=""spanCNMoneyMoney""> "&aryN(Mid(prmtMoney,i,1))&" </span>"&"<span class=""spanCNMoneyUnit""> "&aryF(i)&" </span>"&sNumA
 next
 if prmtType="A" then
  ReplaceMoneyRight=sNumA
 else
  ReplaceMoneyRight=ReplaceCNZeroRight(sNum)
 end if
End Function

Function GetWYIndex(prmtIndex)
 if prmtIndex=1 then
  GetWYIndex=1
 elseif ((prmtIndex-5) mod 8)=0 then
  GetWYIndex=2
 elseif  ((prmtIndex-1) mod 8)=0 then
  GetWYIndex=3
 else
  GetWYIndex=0
 end if
End Function

Function ReplaceCNZeroLeft(prmtStrCNMoney)
 ReplaceCNZeroLeft=prmtStrCNMoney
 ReplaceCNZeroLeft=replace(ReplaceCNZeroLeft,"零仟","零")
 ReplaceCNZeroLeft=replace(ReplaceCNZeroLeft,"零佰","零")
 ReplaceCNZeroLeft=replace(ReplaceCNZeroLeft,"零拾","零")
 dim regExZero
 Set regExZero = New RegExp   ' 创建正则表达式。
 regExZero.IgnoreCase = True   ' 设置是否区分大小写。
 regExZero.Global = True   ' 设置全程匹配。
 regExZero.Pattern = "零+"
 ReplaceCNZeroLeft=regExZero.replace(ReplaceCNZeroLeft,"零")
 ReplaceCNZeroLeft=replace(ReplaceCNZeroLeft,"零万","万")
 ReplaceCNZeroLeft=replace(ReplaceCNZeroLeft,"零亿","亿")
 ReplaceCNZeroLeft=replace(ReplaceCNZeroLeft,"零元","元")
 ReplaceCNZeroLeft=replace(ReplaceCNZeroLeft,"亿万","亿零")
End Function

Function ReplaceCNZeroRight(prmtStrCNMoney)
 ReplaceCNZeroRight=prmtStrCNMoney
 ReplaceCNZeroRight=replace(ReplaceCNZeroRight,"零角","零")
 dim regExZero
 Set regExZero = New RegExp   ' 创建正则表达式。
 regExZero.IgnoreCase = True   ' 设置是否区分大小写。
 regExZero.Global = True   ' 设置全程匹配。
 regExZero.Pattern = "零+分"
 ReplaceCNZeroRight=regExZero.replace(ReplaceCNZeroRight,"")
End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值