# 新写了一个转中文大写金额的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

• 本文已收录于以下专栏：

举报原因： 您举报文章：新写了一个转中文大写金额的ASP函数 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)