怎样把金额转换成英文大写?即100转为one hundred(100分)

  • 主题发起人 usa112233
  • 开始时间
U

usa112233

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样把金额转换成英文大写?即100转为one hundred
 
//不能转小数,好象有最大值限制,因是很久前写的,没仔细看了
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Edit1.Text:=NumberBig(Edit1.Text);
end;

function TForm1.NumberBig(Num: String): String;
Var
i:Integer;
StrTemp1,StrTemp2,Str:String;
NumTemp1:Integer;
//每位数字
do
ubZero,wanzero,ThreeZero:Boolean;
//判断十,个位是否同时为零
OneB:Boolean;
//判断第二位是否为1
unitStr:TStringList;
//单位字符
begin
unitStr:=TStringList.Create;
unitStr.Add('HUNDRED');
unitStr.Add('THOUSAND');
unitStr.Add('MILLION');
StrTemp1:=Num;
For i:=1 To Length(StrTemp1)do
Str:=StrTemp1+Str;
StrTemp1:= Str ;
Str:='';
For i:=1 to Length(StrTemp1)do
begin
NumTemp1:=StrToInt(StrTemp1);
If OneB=True then
begin
OneB:=False;
Continue;
end;
If ((i=1) or (i=4) OR (i=7)) and (StrTemp1[i+1]='1') then
begin
Case NumTemp1 Of
0:StrTemp2:=' TEN ';
1:StrTemp2:=' ELEVEN ';
2:StrTemp2:=' TWELVE ';
3:StrTemp2:=' THIRTEEN ';
4:StrTemp2:=' FOURTEEN ';
5:StrTemp2:=' FIFTEEN ';
6:StrTemp2:=' SIXTEEN ';
7:StrTemp2:=' SEVENTEEN ';
8:StrTemp2:=' EIGHTEEN ';
9:StrTemp2:=' NINETEEN ';
end;
OneB:=True;
End
else
If (i=2) or (i=5) OR (i=8) then
Case NumTemp1 Of
0:StrTemp2:='';
1:StrTemp2:=' TEN ';
2:StrTemp2:=' TWENTY ';
3:StrTemp2:=' THIRTY ';
4:StrTemp2:=' FORTY ';
5:StrTemp2:=' FIFTY ';
6:StrTemp2:=' SIXTY ';
7:StrTemp2:=' SEVENTY ';
8:StrTemp2:=' EIGHTY ';
9:StrTemp2:=' NINETY ';
End
else
Case NumTemp1 Of
0:StrTemp2:='';
1:StrTemp2:='ONE';
2:StrTemp2:='TWO';
3:StrTemp2:='THREE';
4:StrTemp2:='FOUR';
5:StrTemp2:='FIVE';
6:StrTemp2:='SIX';
7:StrTemp2:='SEVEN';
8:StrTemp2:='EIGHT';
9:StrTemp2:='NINE';
End ;
If StrTemp2='' then
//当前位是否为零
wanzero:=True;
If i=3 then
begin
If wanzero=False then
begin
Ifdo
ubZero=True then
StrTemp2:=StrTemp2+' '+unitStr.Strings[0]+' AND '
else
StrTemp2:=StrTemp2+' '+unitStr.Strings[0];
End
else
begin
Ifdo
ubZero=True then
StrTemp2:=StrTemp2+' AND ';
end;
End
else
If (i=4) and (wanzero=False) then
StrTemp2:=StrTemp2+' '+unitStr.Strings[1]+' '
else
If (i=5) and (wanzero=False) and (ThreeZero=False) then
StrTemp2:=StrTemp2+' '+unitStr.Strings[1]+' '
else
If (i=6) and (wanzero=False) then
begin
If ThreeZero=False then
StrTemp2:=StrTemp2+' '+unitStr.Strings[0]+' '+unitStr.Strings[1]+' '
else
StrTemp2:=StrTemp2+' '+unitStr.Strings[0]+' ';
End
else
If i=7 then
StrTemp2:=StrTemp2+' '+unitStr.Strings[2]+' '
else
If (i=9) and (wanzero=False) then
StrTemp2:=StrTemp2+' '+unitStr.Strings[0];
If StrTemp2<>'' then
//某位之前的数是否都为零
do
ubZero:=True;
If (i>3) and (StrTemp2<>'') then
//4,5,6位是否同时为零
ThreeZero:=True;
wanzero:=False;
Str:=StrTemp2+Str;
end;
unitStr.Free;
Result:=Str;
end;
 
我写过一个把金额转换成中文大写的,程序如下,你把其中的中文改成英文试试,
如有什么问题我们再讨论!
function xTOd(i:Real):string;
const d='零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿';
var m,k:string;

j:integer;
begin

k:='';
m:=inttostr(round(i*100));

for j:=length(m)do
wnto 1do

k:=k+d[(strtoint(m[Length(m)-j+1])+1)*2-1]+
d[(strtoint(m[Length(m)-j+1])+1)*2]+d[(10+j)*2-1]+d[(10+j)*2];
xTOd:=k;
end;
 
如果是任意数字转英文大写,先判断它的位数,再用div和mod函数来判断。
 
多人接受答案了。
 
如果是任意数字转英文大写,那位高手写全了,再送100分!
 
顶部