我的转换结果是:ONE HANDRED AND TWENTY THREE AND CENTS ELEVEN 不知合不合要求?
TO:hawksoft(明月清风) .cn 要分无所谓,你发给我再开几贴给你分。
奇闻共欣赏,异议相与析 --------------------------------------------------------------------------------- 下面代码是转换成中文的 改几个字就可以了function ConvertNumber(Value:Extended): string; var ps: string; ns: string; ns1, ns2, ns3: string; i: integer; iValue: LongInt; PValue : Integer; da: array [0 .. 12] of string; na: array [0 .. 10] of string; ps0: boolean; begin da[0] := ''; da[1] := '拾'; da[2] := '佰'; da[3] := '仟'; na[0] := '零'; na[1] := '壹'; na[2] := '贰'; na[3] := '叁'; na[4] := '肆'; na[5] := '伍'; na[6] := '陆'; na[7] := '柒'; na[8] := '捌'; na[9] := '玖'; ps := ''; ns := ''; ns1 := ''; ns2 := ''; ns3 := ''; if Value <> Trunc(Value) then begin pValue := Trunc((Value - Trunc(Value))*100+0.5); ps := na[pValue div 10] + '角'; if (pValue mod 10) <> 0 then ps := ps+na[pValue mod 10] + '分'; end; i := 0; iValue := Trunc(Value); if IValue = 0 then ns := '零元' else begin ps0 := False; repeat if (IValue mod 10 <> 0) then begin ns1 := na[Ivalue mod 10] + da[i] + ns1; ps0 := True; end else if ps0 then begin ns1 := '零'+ns1; ps0 := False; end; iValue := IValue Div 10; inc(i); until (iValue = 0) or (i > 3); ns := ns1; if iValue <> 0 then begin ps0 := False; i := 0; repeat if (IValue mod 10 <> 0) then begin ns2 := na[Ivalue mod 10] + da[i] + ns2; ps0 := True; end else if ps0 then begin ns2 := '零'+ns2; ps0 := False; end; iValue := IValue Div 10; inc(i); until (iValue = 0) or (i > 3); if ns2 <> '' then ns := ns2 + '万' + ns; end; if iValue <> 0 then begin ps0 := False; i := 0; repeat if (IValue mod 10 <> 0) then begin ns3 := na[Ivalue mod 10] + da[i] + ns3; ps0 := True; end else if ps0 then begin ns2 := '零'+ns3; ps0 := False; end; iValue := IValue Div 10; inc(i); until (iValue = 0) or (i > 3); end; if ns3 <> '' then ns := ns3 + '亿'+ ns; ns := ns + '元'; end; Result := ns + ps + '整'; end;function GetDigit(Value: string): string; var i: integer; begin Result := ''; for i := 1 to Length(Value) do if Value[i] in ['0'..'9', '.'] then Result := Result + Value[i]; end;
{**************************************************} { } { Number to letters unit version 1.1 } { } { copyright (C) Dylan Thomas 2000 } { } { License: No significant restrictions. } { } { Language: US. English } { } {**************************************************} unit NumberToLetters; interface {var Calls: Integer;} //Use to count number of recursive calls (* This function returns the written equivalent of a number. *) function NumToLetters(Number: Real): string; implementation uses SysUtils; type TNumberStr = string[13]; const Numbers: array[1..19] of TNumberStr = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'); Tenths: array[1..9] of TNumberStr = ('ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'); ErrorString = 'not in valid range'; Min = 1.00; Max = 4294967295.99; function NumToLetters(Number: Real): string; function RecurseNumber(N: LongWord): string; begin {Inc(Calls);} //Use to count the number of recursive calls case N of 1..19: Result := Numbers[N]; 20..99: Result := Tenths[N div 10] + ' ' + RecurseNumber(N mod 10); 100..999: Result := Numbers[N div 100] + ' hundred ' + RecurseNumber(N mod 100); 1000..999999: Result := RecurseNumber(N div 1000) + ' thousand ' + RecurseNumber(N mod 1000); 1000000..999999999: Result := RecurseNumber(N div 1000000) + ' million ' + RecurseNumber(N mod 1000000); 1000000000..4294967295: Result := RecurseNumber(N div 1000000000) + ' billion ' + RecurseNumber(N mod 1000000000); end; {Case N of} end; {RecurseNumber} begin {Calls := 0;} //Use to count the number of recursive calls if (Number >= Min) and (Number <= Max) then begin Result := RecurseNumber(Round(Int(Number))); {Added for cents in a currency value} if not(Frac(Number) = 0.00) then Result := Result + ' and ' + IntToStr(Round(Frac(Number) * 100)) + '/100'; end else raise ERangeError.CreateFmt('%g ' + ErrorString + ' %g..%g', [Number, Min, Max]); end;{NumToLetters} end.
再试试这个 function Tform1.English(lcnum:string):string; type arr=array[1..9,1..3] of string; var num:arr; lclast,temp:string; i,code,len,lntimes,lnhundred,lnten,lnone,lntempnum:integer; begin lntimes:=0; lclast:=''; num[1,1]:='ONE'; num[1,2]:='ELEVEN'; num[1,3]:='TEN'; num[2,1]:='TWO'; num[2,2]:='TWELVE'; num[2,3]:='TWENTY'; num[3,1]:='THREE'; num[3,2]:='THIRTEEN'; num[3,3]:='THIRTY'; num[4,1]:='FOUR'; num[4,2]:='FOURTEEN'; num[4,3]:='FORTY'; num[5,1]:='FIVE'; num[5,2]:='FIFTEEN'; num[5,3]:='FIFTY'; num[6,1]:='SIX'; num[6,2]:='SIXTEEN'; num[6,3]:='SIXTY'; num[7,1]:='SEVEN'; num[7,2]:='SEVENTEEN'; num[7,3]:='SEVENTY'; num[8,1]:='EIGHT'; num[8,2]:='EIGHTEEN'; num[8,3]:='EIGHTY'; num[9,1]:='NINE'; num[9,2]:='NINETEEN'; num[9,3]:='NINETY'; len:=length(lcnum); for i:=1 to 12-len do lcnum:=concat('0',lcnum); for i:=0 to 3 do begin temp:=copy(lcnum,1+3*i,3); val(temp,lntempnum,code); lntimes:=lntimes+1; if lntempnum=0 then continue; lnhundred:=lntempnum div 100; lnten:=(lntempnum div 10) mod 10; lnone:=lntempnum mod 10; if lnhundred<>0 then lclast:=concat(lclast,' ',num[lnhundred,1],' HUNDRED'); if (length(trim(lclast))<>0) and (lnhundred<>0) then lclast:=concat(lclast,' AND'); if (lntimes=4) and (lnhundred=0) and (length(trim(lclast))<>0) then lclast:=concat(lclast,' AND'); case lnten of 0: begin if lnone<>0 then lclast:=concat(lclast,' ',num[lnone,1]) else begin temp:=copy(lclast,length(lclast)-2,3); if temp='AND' then lclast:=copy(lclast,1,length(lclast)-3); end;//case 0 else end;//case 0 1: begin if lnone<>0 then lclast:=concat(lclast,' ',num[lnone,2]) else lclast:=concat(lclast,' ',num[1,3]); end;//case 1 else if lnone<>0 then lclast:=concat(lclast,' ',num[lnten,3],'-',num[lnone,1]) else lclast:=concat(lclast,' ',num[lnten,3]); end;//case1 case lntimes of 1:lclast:=concat(lclast,' BILLION'); 2:lclast:=concat(lclast,' MILLION'); 3:lclast:=concat(lclast,' THOUSAND'); end;//case2 end;//for result:=lclast; end;
不知合不合要求?
要分无所谓,你发给我再开几贴给你分。
---------------------------------------------------------------------------------
下面代码是转换成中文的
改几个字就可以了function ConvertNumber(Value:Extended): string;
var
ps: string;
ns: string;
ns1, ns2, ns3: string;
i: integer;
iValue: LongInt;
PValue : Integer;
da: array [0 .. 12] of string;
na: array [0 .. 10] of string;
ps0: boolean;
begin
da[0] := '';
da[1] := '拾';
da[2] := '佰';
da[3] := '仟';
na[0] := '零';
na[1] := '壹';
na[2] := '贰';
na[3] := '叁';
na[4] := '肆';
na[5] := '伍';
na[6] := '陆';
na[7] := '柒';
na[8] := '捌';
na[9] := '玖';
ps := '';
ns := '';
ns1 := '';
ns2 := '';
ns3 := '';
if Value <> Trunc(Value) then
begin
pValue := Trunc((Value - Trunc(Value))*100+0.5);
ps := na[pValue div 10] + '角';
if (pValue mod 10) <> 0 then
ps := ps+na[pValue mod 10] + '分';
end;
i := 0;
iValue := Trunc(Value);
if IValue = 0 then
ns := '零元'
else
begin
ps0 := False;
repeat
if (IValue mod 10 <> 0) then
begin
ns1 := na[Ivalue mod 10] + da[i] + ns1;
ps0 := True;
end
else if ps0 then
begin
ns1 := '零'+ns1;
ps0 := False;
end;
iValue := IValue Div 10;
inc(i);
until (iValue = 0) or (i > 3);
ns := ns1;
if iValue <> 0 then
begin
ps0 := False;
i := 0;
repeat
if (IValue mod 10 <> 0) then
begin
ns2 := na[Ivalue mod 10] + da[i] + ns2;
ps0 := True;
end
else if ps0 then
begin
ns2 := '零'+ns2;
ps0 := False;
end;
iValue := IValue Div 10;
inc(i);
until (iValue = 0) or (i > 3);
if ns2 <> '' then
ns := ns2 + '万' + ns;
end;
if iValue <> 0 then
begin
ps0 := False;
i := 0;
repeat
if (IValue mod 10 <> 0) then
begin
ns3 := na[Ivalue mod 10] + da[i] + ns3;
ps0 := True;
end
else if ps0 then
begin
ns2 := '零'+ns3;
ps0 := False;
end;
iValue := IValue Div 10;
inc(i);
until (iValue = 0) or (i > 3);
end;
if ns3 <> '' then
ns := ns3 + '亿'+ ns;
ns := ns + '元';
end;
Result := ns + ps + '整';
end;function GetDigit(Value: string): string;
var
i: integer;
begin
Result := '';
for i := 1 to Length(Value) do
if Value[i] in ['0'..'9', '.'] then
Result := Result + Value[i];
end;
{ }
{ Number to letters unit version 1.1 }
{ }
{ copyright (C) Dylan Thomas 2000 }
{ }
{ License: No significant restrictions. }
{ }
{ Language: US. English }
{ }
{**************************************************} unit NumberToLetters; interface {var Calls: Integer;} //Use to count number of recursive calls (* This function returns the written equivalent of a number. *)
function NumToLetters(Number: Real): string; implementation
uses SysUtils; type TNumberStr = string[13]; const
Numbers: array[1..19] of TNumberStr = ('one', 'two', 'three', 'four',
'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve',
'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen',
'nineteen'); Tenths: array[1..9] of TNumberStr = ('ten', 'twenty', 'thirty', 'forty',
'fifty', 'sixty', 'seventy', 'eighty', 'ninety'); ErrorString = 'not in valid range'; Min = 1.00;
Max = 4294967295.99; function NumToLetters(Number: Real): string; function RecurseNumber(N: LongWord): string;
begin
{Inc(Calls);} //Use to count the number of recursive calls
case N of
1..19:
Result := Numbers[N];
20..99:
Result := Tenths[N div 10] + ' ' + RecurseNumber(N mod 10);
100..999:
Result := Numbers[N div 100] + ' hundred ' + RecurseNumber(N mod 100);
1000..999999:
Result := RecurseNumber(N div 1000) + ' thousand ' +
RecurseNumber(N mod 1000);
1000000..999999999: Result := RecurseNumber(N div 1000000) + ' million '
+ RecurseNumber(N mod 1000000);
1000000000..4294967295: Result := RecurseNumber(N div 1000000000) +
' billion ' + RecurseNumber(N mod 1000000000);
end; {Case N of}
end; {RecurseNumber} begin
{Calls := 0;} //Use to count the number of recursive calls
if (Number >= Min) and (Number <= Max) then
begin
Result := RecurseNumber(Round(Int(Number)));
{Added for cents in a currency value}
if not(Frac(Number) = 0.00) then
Result := Result + ' and ' + IntToStr(Round(Frac(Number) * 100)) +
'/100';
end
else
raise ERangeError.CreateFmt('%g ' + ErrorString + ' %g..%g',
[Number, Min, Max]);
end;{NumToLetters} end.
function Tform1.English(lcnum:string):string;
type
arr=array[1..9,1..3] of string;
var
num:arr;
lclast,temp:string;
i,code,len,lntimes,lnhundred,lnten,lnone,lntempnum:integer;
begin
lntimes:=0;
lclast:='';
num[1,1]:='ONE';
num[1,2]:='ELEVEN';
num[1,3]:='TEN';
num[2,1]:='TWO';
num[2,2]:='TWELVE';
num[2,3]:='TWENTY';
num[3,1]:='THREE';
num[3,2]:='THIRTEEN';
num[3,3]:='THIRTY';
num[4,1]:='FOUR';
num[4,2]:='FOURTEEN';
num[4,3]:='FORTY';
num[5,1]:='FIVE';
num[5,2]:='FIFTEEN';
num[5,3]:='FIFTY';
num[6,1]:='SIX';
num[6,2]:='SIXTEEN';
num[6,3]:='SIXTY';
num[7,1]:='SEVEN';
num[7,2]:='SEVENTEEN';
num[7,3]:='SEVENTY';
num[8,1]:='EIGHT';
num[8,2]:='EIGHTEEN';
num[8,3]:='EIGHTY';
num[9,1]:='NINE';
num[9,2]:='NINETEEN';
num[9,3]:='NINETY';
len:=length(lcnum);
for i:=1 to 12-len do
lcnum:=concat('0',lcnum);
for i:=0 to 3 do
begin
temp:=copy(lcnum,1+3*i,3);
val(temp,lntempnum,code);
lntimes:=lntimes+1;
if lntempnum=0 then
continue;
lnhundred:=lntempnum div 100;
lnten:=(lntempnum div 10) mod 10;
lnone:=lntempnum mod 10;
if lnhundred<>0 then
lclast:=concat(lclast,' ',num[lnhundred,1],' HUNDRED');
if (length(trim(lclast))<>0) and (lnhundred<>0) then
lclast:=concat(lclast,' AND');
if (lntimes=4) and (lnhundred=0) and (length(trim(lclast))<>0) then
lclast:=concat(lclast,' AND');
case lnten of
0:
begin
if lnone<>0 then
lclast:=concat(lclast,' ',num[lnone,1])
else
begin
temp:=copy(lclast,length(lclast)-2,3);
if temp='AND' then
lclast:=copy(lclast,1,length(lclast)-3);
end;//case 0 else
end;//case 0
1:
begin
if lnone<>0 then
lclast:=concat(lclast,' ',num[lnone,2])
else
lclast:=concat(lclast,' ',num[1,3]);
end;//case 1
else
if lnone<>0 then
lclast:=concat(lclast,' ',num[lnten,3],'-',num[lnone,1])
else
lclast:=concat(lclast,' ',num[lnten,3]);
end;//case1
case lntimes of
1:lclast:=concat(lclast,' BILLION');
2:lclast:=concat(lclast,' MILLION');
3:lclast:=concat(lclast,' THOUSAND');
end;//case2
end;//for
result:=lclast;
end;