- 作者:zhaozj
- 发表时间:2020-12-23 10:59
- 来源:未知
刚写的一个函数,但只能对"亿"以下的数值有效.如果超过Long类型的数值范围则转换会出错!!!!函数直接使用ChangeMoney(数值)即可!!得到的则是转换后的大写数额以下是第一次写的:对0不起隐藏作用<%Response.Write(ChangeMoney(235))Function ChangeMoney(sMoney)On Error Resume NextDim sToDim iInt,iMod'取得整数sMoney=sMoney / 1If Err.Number<>0 Then Response.Write "数值太大!!不能转换!!" Response.EndEnd IfiInt=Len(sMoney)If iInt>5 Then '超过万 iMod=iInt-4 sTo=ChangeTo(sMoney,iMod,1) iMod=4 sTo=sTo&"万" sTo=sTo&ChangeTo(sMoney,iMod,0)&"元整"Else sTo=ChangeTo(sMoney,iInt,0)&"元整"End iFChangeMoney=sToEnd FunctionFunction ChangeTo(sMoney,iNum,iTo) Dim sTr Do While iNum>0 sTr=sTr&GetMoney(sMoney,iNum,iTo) iNum=iNum-1 Loop ChangeTo=sTrEnd FunctionFunction GetMoney(sMoney,iNum,iTo) Dim sMen,sStr,iLen iLen=Len(sMoney)-(iNum+iTo*5)+1+iTo sMen="零壹贰叄肆伍陆柒捌玖" Select Case iNum Case 5 If iTo=1 Then sStr="亿" Else sStr="万" End If Case 4 sStr="千" Case 3 sStr="百" Case 2 sStr="十" Case else sStr="" End Select GetMoney=Mid(sMen,Cint(Mid(sMoney,iLen,1))+1,1)&sStrEnd Function%>
最后修改的,对连续的0起隐藏作用:
<%Response.Write(ChangeMoney(2032400))
Function ChangeMoney(sMoney)On Error Resume NextDim sToDim iInt,iMod'取得整数sMoney=sMoney / 1If Err.Number<>0 Then Response.Write "数值太大!!不能转换!!" Response.EndEnd IfIf Left(sMoney,1)="0" Then Response.Write "输入错误的数值!开头不能是0!" Response.EndEnd IfiInt=Len(sMoney)If iInt>5 Then '超过万 iMod=iInt-4 sTo=ChangeTo(sMoney,iMod,1) iMod=4 sTo=sTo&"万" sTo=sTo&ChangeTo(sMoney,iMod,0)&"元整"Else sTo=ChangeTo(sMoney,iInt,0)&"元整"End iFChangeMoney=sToEnd Function
Function ChangeTo(sMoney,iNum,iTo) Dim sTr Do While iNum>0 sTr=sTr&GetMoney(sMoney,iNum,iTo) iNum=iNum-1 Loop ChangeTo=sTrEnd Function
Function GetMoney(sMoney,iNum,iTo) Dim sMen,sStr,iLen,sNum,sVal iLen=Len(sMoney)-(iNum+iTo*5)+1+iTo sMen="零壹贰叄肆伍陆柒捌玖" sVal=" 十百千万" sStr=Mid(sVal,iNum,1) If iNum=5 And iTo=1 Then '亿 sStr="亿" End If sNum=Mid(sMoney,iLen,1) If sNum<>"0" Then GetMoney=Mid(sMen,Cint(sNum)+1,1)&trim(sStr) Else GetMoney="" End IfEnd Function%>