chen_hua790618
02-08-06, 01:37 PM
你可以看一下如下代码:
Total1:=需要转换的数值金额;
Capital:="壹":"贰":"叁":"肆":"伍":"陆":"柒":"捌":"玖";
costCap:="";
REM {从亿到千亿};
qy:=@TextToNumber(@Right(@Text(@Integer(Total1/100000000000));1));
@If(qy>0;@Set("costCap";costCap+@Subset(@Subset(Capital;qy);-1)+"千");"");
by:=@TextToNumber(@Right(@Text(@Integer(Total1/10000000000));1));
@If(by>0;@Set("costCap";costCap+@Subset(@Subset(Capital;by);-1)+"百");"");
sy:=@TextToNumber(@Right(@Text(@Integer(Total1/1000000000));1));
@If(sy>0;@Set("costCap";costCap+@Subset(@Subset(Capital;sy);-1)+"拾");"");
yi:=@TextToNumber(@Right(@Text(@Integer(Total1/100000000));1));
@If(yi>0;@Set("costCap";costCap+@Subset(@Subset(Capital;yi);-1));"");
@If(Total1/100000000>=1;@Set("costCap";costCap+"亿");"");
REM {从万到千万};
qw:=@TextToNumber(@Right(@Text(@Integer(Total1/10000000));1));
@If(qw>0;@Set("costCap";costCap+@Subset(@Subset(Capital;qw);-1)+"千");"");
bw:=@TextToNumber(@Right(@Text(@Integer(Total1/1000000));1));
@If(bw>0;@Set("costCap";costCap+@Subset(@Subset(Capital;bw);-1)+"百");"");
sw:=@TextToNumber(@Right(@Text(@Integer(Total1/100000));1));
@If(sw>0;@Set("costCap";costCap+@Subset(@Subset(Capital;sw);-1)+"拾");"");
w:=@TextToNumber(@Right(@Text(@Integer(Total1/10000));1));
@If(w>0;@Set("costCap";costCap+@Subset(@Subset(Capital;w);-1));"");
@If(Total1/10000>=1;@Set("costCap";costCap+"万");"");
REM {从元到千元};
q:=@TextToNumber(@Right(@Text(@Integer(Total1/1000));1));
@If(q>0;@Set("costCap";costCap+@Subset(@Subset(Capital;q);-1)+"千");"");
b:=@TextToNumber(@Right(@Text(@Integer(Total1/100));1));
@If(b>0;@Set("costCap";costCap+@Subset(@Subset(Capital;b);-1)+"百");"");
s:=@TextToNumber(@Right(@Text(@Integer(Total1/10));1));
@If(s>0;@Set("costCap";costCap+@Subset(@Subset(Capital;s);-1)+"拾");"");
y:=@TextToNumber(@Right(@Text(@Integer(Total1));1));
@If(y>0;@Set("costCap";costCap+@Subset(@Subset(Capital;y);-1));"");
@If(Total1>=1 & Total1=@Integer(Total1);@Set("costCap";costCap+"元整");Total1>=1;@Set("costCap";costCap+"元");"");
REM {角、分};
j:=@TextToNumber(@Left(@Right(@Trim(@Text(Total1));".")+"00";1));
@If(j>0;@Set("costCap";costCap+@Subset(@Subset(Capital;j);-1)+"角");"");
f:=@TextToNumber(@Right(@Left(@Right(@Trim(@Text(Total1));".")+"00";2);1));
@If(f>0;@Set("costCap";costCap+@Subset(@Subset(Capital;f);-1)+"分");"");
@If(@IsError(costCap);"";costCap)
Function NumberToCapital(money As String) As String '
'功 能:实现人民币大写金额转换
Dim x As String, y As String
Const zimu = ".sbqwsbqysbqwsbq" '定义位置代码
Const letter = "0123456789sbqwy.zjf" '定义汉字缩写
Const upcase = "零壹贰叁肆伍陆柒捌玖拾佰仟万亿元整角分" '定义大写汉字
Dim temp As String
Dim tmp$
Dim j%
temp = money
If Trim(temp) = "" Then
Msgbox "非数字转换!请输入有效的数字", 64, "错误提示"
Exit Function
End If
j% = 0
For i = 1 To Len(money)
tmp$ = Mid(money,i,1)
Select Case tmp$
Case "."
j% = j% + 1
Case "1","2","3","4","5","6","7","8","9", "0"
'正常
Case Else
Msgbox "非数字转换!请输入有效的数字", 64, "错误提示"
Exit Function
End Select
If j% > 1 Then
Msgbox "非数字转换!请输入有效的数字", 64, "错误提示"
Exit Function
End If
Next i
'If Not Isnumeric(money) > 16 Then Msgbox "非数字转换!请输入有效的数字", 64, "错误提示": Exit Function
If Instr(temp, ".") > 0 Then temp = Left(temp, Instr(temp, ".") - 1)
If Len(temp) > 16 Then Msgbox "数目太大,无法换算!请输入一亿亿以下的数字", 64, "错误提示": Exit Function '只能转换一亿亿元以下数目的货币!
x = Format(money, "0.00") '格式化货币
y = ""
For i = 1 To Len(x) - 3
y = y & Mid(x, i, 1) & Mid(zimu, Len(x) - 2 - i, 1)
Next
If Right(x, 3) = ".00" Then
y = y & "z" '***元整
Else
y = y & Left(Right(x, 2), 1) & "j" & Right(x, 1) & "f" '*元*角*分
End If
y = Replace(y, "0q", "0") '避免零千(如:40200肆萬零千零贰佰)
y = Replace(y, "0b", "0") '避免零百(如:41000肆萬壹千零佰)
y = Replace(y, "0s", "0") '避免零十(如:204贰佰零拾零肆)
Do While y <> Replace(y, "00", "0")
y = Replace(y, "00", "0") '避免双零(如:1004壹仟零零肆)
Loop
y = Replace(y, "0y", "y") '避免零億(如:210億 贰佰壹十零億)
y = Replace(y, "0w", "w") '避免零萬(如:210萬 贰佰壹十零萬)
'避免壹十(如:14壹拾肆;10壹拾)
If Len(x) = 5 And Left(y, 1) = "1" Then
y = Right(y, Len(y) - 1)
End If
'避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分)
If Len(x) = 4 Then
y = Replace(y, "0.", "")
End If
For i = 1 To 19
y = Replace(y, Mid(letter, i, 1), Mid(upcase, i, 1)) '大写汉字
Next
'Com_NumberToCapital = y
'Msgbox Com_NumberToCapital, 64, "错误提示"
NumberToCapital = y
End Function
susufangcherry
02-08-06, 02:02 PM
:victory::handshake:hug::kiss:
:-( 我最近也在学开发,楼主能不能给我一个用LS转换的DEMO
wsqrock ◎gmail.com (wsqrock@gmail.com) ◎请改成@
[ 本帖最后由 江南大米 于 2007-2-7 02:39 PM 编辑 ]
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.