人民币金额转换例程

2018-06-17 17:16:39来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

'调用方法Text2=ChMoney(Val(Text1))
'名称:CCh
'得到一位数字N1的汉字大写
'0返回""
PrivateFunctionCCh(N1)AsString
SelectCaseN1
Case0
CCh="零"
Case1
CCh="壹"
Case2
CCh="贰"
Case3
CCh="叁"
Case4
CCh="肆"
Case5
CCh="伍"
Case6
CCh="陆"
Case7
CCh="柒"
Case8
CCh="捌"
Case9
CCh="玖"
EndSelect
EndFunction
'名称:ChMoney
'得到数字N1的汉字大写
'最大为千万位
'O返回""
PublicFunctionChMoney(N1)AsString
DimtMoneyAsString
DimlMoneyAsString
Dimtn'小数位置
Dims1AsString'临时STRING小数部分
Dims2AsString'1000以内
Dims3AsString'10000
IfN1=0Then
ChMoney=""
ExitFunction
EndIf
IfN1<0Then
ChMoney="负" ChMoney(Abs(N1))
ExitFunction
EndIf
tMoney=Trim(Str(N1))
tn=InStr(tMoney,".")'小数位置
s1=""
Iftn<>0Then
ST1=Right(tMoney,Len(tMoney)-tn)
IfST1<>""Then
t1=Left(ST1,1)
ST1=Right(ST1,Len(ST1)-1)
Ift1<>"0"Then
s1=s1 CCh(Val(t1)) "角"
EndIf
IfST1<>""Then
t1=Left(ST1,1)
s1=s1 CCh(Val(t1)) "分"
EndIf
EndIf
ST1=Left(tMoney,tn-1)
Else
ST1=tMoney
EndIf
s2=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s2=CCh(Val(t1)) s2
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "拾" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "佰" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "仟" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
s3=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s3=CCh(Val(t1)) s3
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "拾" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "佰" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "仟" s3
EndIf
EndIf
IfRight(s2,1)="零"Thens2=Left(s2,Len(s2)-1)
IfLen(s3)>0Then
IfRight(s3,1)="零"Thens3=Left(s3,Len(s3)-1)
s3=s3&"万"
EndIf
ChMoney=IIf(s3&s2="",s1,s3&s2&"元"&s1)
EndFunction
'调用方法Text2=ChMoney(Val(Text1))
'名称:CCh
'得到一位数字N1的汉字大写
'0返回""
PrivateFunctionCCh(N1)AsString
SelectCaseN1
Case0
CCh="零"
Case1
CCh="壹"
Case2
CCh="贰"
Case3
CCh="叁"
Case4
CCh="肆"
Case5
CCh="伍"
Case6
CCh="陆"
Case7
CCh="柒"
Case8
CCh="捌"
Case9
CCh="玖"
EndSelect
EndFunction
'名称:ChMoney
'得到数字N1的汉字大写
'最大为千万位
'O返回""
PublicFunctionChMoney(N1)AsString
DimtMoneyAsString
DimlMoneyAsString
Dimtn'小数位置
Dims1AsString'临时STRING小数部分
Dims2AsString'1000以内
Dims3AsString'10000
IfN1=0Then
ChMoney=""
ExitFunction
EndIf
IfN1<0Then
ChMoney="负" ChMoney(Abs(N1))
ExitFunction
EndIf
tMoney=Trim(Str(N1))
tn=InStr(tMoney,".")'小数位置
s1=""
Iftn<>0Then
ST1=Right(tMoney,Len(tMoney)-tn)
IfST1<>""Then
t1=Left(ST1,1)
ST1=Right(ST1,Len(ST1)-1)
Ift1<>"0"Then
s1=s1 CCh(Val(t1)) "角"
EndIf
IfST1<>""Then
t1=Left(ST1,1)
s1=s1 CCh(Val(t1)) "分"
EndIf
EndIf
ST1=Left(tMoney,tn-1)
Else
ST1=tMoney
EndIf
s2=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s2=CCh(Val(t1)) s2
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "拾" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "佰" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "仟" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
s3=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s3=CCh(Val(t1)) s3
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "拾" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "佰" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "仟" s3
EndIf
EndIf
IfRight(s2,1)="零"Thens2=Left(s2,Len(s2)-1)
IfLen(s3)>0Then
IfRight(s3,1)="零"Thens3=Left(s3,Len(s3)-1)
s3=s3&"万"
EndIf
ChMoney=IIf(s3&s2="",s1,s3&s2&"元"&s1)
EndFunction->

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:VB在CAI编程中的应用

下一篇:HierarchicalFlexGrid控件