S
samboy111
Unregistered / Unconfirmed
GUEST, unregistred user!
//不能转小数,好象有最大值限制,因是很久前写的,没仔细看了
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; //每位数字
DoubZero,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
If DoubZero=True Then
StrTemp2:=StrTemp2+' '+unitStr.Strings[0]+' AND '
Else
StrTemp2:=StrTemp2+' '+unitStr.Strings[0];
End
Else
Begin
If DoubZero=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 //某位之前的数是否都为零
DoubZero:=True;
If (i>3) and (StrTemp2<>'') Then //4,5,6位是否同时为零
ThreeZero:=True;
wanzero:=False;
Str:=StrTemp2+Str;
END;
unitStr.Free;
Result:=Str;
end;
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; //每位数字
DoubZero,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
If DoubZero=True Then
StrTemp2:=StrTemp2+' '+unitStr.Strings[0]+' AND '
Else
StrTemp2:=StrTemp2+' '+unitStr.Strings[0];
End
Else
Begin
If DoubZero=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 //某位之前的数是否都为零
DoubZero:=True;
If (i>3) and (StrTemp2<>'') Then //4,5,6位是否同时为零
ThreeZero:=True;
wanzero:=False;
Str:=StrTemp2+Str;
END;
unitStr.Free;
Result:=Str;
end;