下例转换结果: 4002.02->肆仟元零贰分
40100.00->肆万零一佰元正
procedure ReplaceAll(var tag: string;
str1,str2: string);
var
i: integer;
begin
while pos(str1,tag)<>0do
begin
i:=pos(str1,tag);
delete(tag,i,length(str1));
insert(str1,tag,i);
end;
end;
function change2captal(x: real):string;
const
digits: array [0..9] of string = ('零','壹','贰','叁','肆',
'伍','陆','柒','捌','玖');
positions: array [1..11] of string = ('亿','仟','佰','拾','万',
'仟','佰','拾','元','角','分');
var
s: string;
i,j: integer;
begin
s:=format('%9.2f',[x]);
result:='';
for i:=1 to length(s)do
begin
if s=' ' then
continue;
result:=result+digits[ord(s)-48]+positions;
end;
ReplaceAll(result, '零仟', '零');
ReplaceAll(result,'零佰','零');
ReplaceAll(result,'零十','零');
ReplaceAll(result,'零角','零');
ReplaceAll(result,'零分','');
while pos('零零',result)<>0do
delete(result,pos('零零',result),2);
ReplaceAll(result,'零亿','亿');
ReplaceAll(reuslt,'零万','万');
ReplaceAll(result,'零元','元');
ReplaceAll(result,'亿万','亿');
if copy(result,length(result)-1,2)='零' then
result:=copy(result,1,length(result)-2);
if copy(result,length(result)-1,2)<>'分' then
result:=result+'正';
end;