...
王寒松老兄的有bug:
10101001 得到: 壹仟零壹拾零壹仟零壹元整 (没有“万”字)
--------------------------------------------------------------
看我的(我的要小于一万亿,最小到分,没有到厘):
需要uses math;
function ToChineseMoney(num:double):string;
const
digit:array[0..9] of string=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
decade:array[0..13] of string=('分','角','元','拾','百','千','万','拾','百','千','亿','拾','百','千');
var
intpart,power10:int64;
d,i:integer;
n:0..9;
last0,band0:boolean;
begin
if(num<0.01)then
begin
result:=digit[0]+'元整';
exit;
end;
d:=trunc(log10(num));
if(d>11)then
raise Exception.Create('超过了能翻译的位数(必须小于1万亿)');
intpart:=Trunc(num*100);
d:=trunc(log10(intpart));
power10:=1;
for i:=1 to d do
power10:=power10*10;
result:='';
last0:=false;
band0:=true;
while d>=0do
begin
n:=integer(intpart div power10);
band0:=band0 and (n=0);
if(n<>0)then
begin
if(last0)then
result:=result+digit[0]+digit[n]+decade[d]
else
result:=result+digit[n]+decade[d];
last0:=false;
end
else
begin
if(d>5)then
begin
last0:=true;
if ((d-2) mod 4)=0 then
if(not band0)then
result:=result+decade[d];
end
else
if(d=2)and(result<>'')then
begin
result:=result+decade[2];
last0:=false;
end
else
last0:=true;
end;
if((d-2)mod 4)=0 then
band0:=true;
intpart:=intpart mod power10;
power10:=power10 div 10;
d:=d-1;
end;
if(result<>'')then
result:=result+'整';
end;