谁有人民币转大写的代码?谢谢(100分)

P

PoeChan

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有人民币转大写的代码?谢谢
请用以下两个数字试验:
1000.25 壹千元两角五分整
0.9 玖角整
 
function ToBigRMB(RMB: string): string;
const
BigNumber='零壹贰叁肆伍陆柒捌玖';
BigUnit='万仟佰拾亿仟佰拾万仟佰拾元';
{共可表示13为金额}
var nLeft, nRigth, lTemp, rTemp, BigNumber1, BigUnit1: string;
I: Integer;
begin
{取整数和小数部分}
RMB:=FormatCurr('0.00', StrToFloat(RMB));
nLeft:=copy(RMB, 1, Pos('.', RMB) - 1);
nRigth:=copy(RMB, Pos('.', RMB) + 1, 2);
for I:=1 to Length(nLeft) do
begin
BigNumber1:=copy(BigNumber, StrToInt(nLeft) * 2 + 1, 2);
BigUnit1:=copy(BigUnit, (Trunc(Length(BigUnit) / 2) - Length(nleft) + I - 1) * 2 + 1, 2);
if (BigNumber1='零') and ((copy(lTemp, Length(lTemp)- 1, 2))='零') then
lTemp:=copy(lTemp, 1, Length(lTemp) - 2);
if (BigNumber1='零') and ((BigUnit1='亿') or (BigUnit1='万') or (BigUnit1='元')) then
begin
BigNumber1:=BigUnit1;
if BigUnit1<>'元' then
BigUnit1:='零'
else
BigUnit1:='';
end;
if (BigNumber1='零') and (BigUnit1<>'亿') and (BigUnit1<>'万') and (BigUnit1<>'元') then
BigUnit1:='';
lTemp:=lTemp + BigNumber1 + BigUnit1;
if Pos('亿万', lTemp)<>0 then
Delete(lTemp, Pos('亿万', lTemp) + 2, 2);
{转换小数部分}
if StrToInt(nRigth[1])<>0 then
rTemp:=copy(BigNumber, StrToInt(nRigth[1]) * 2 + 1, 2) + '角';
if StrToInt(nRigth[2])<>0 then
begin
if StrToInt(nRigth[1])=0 then
rTemp:='零';
rTemp:=rTemp + copy(BigNumber, StrToInt(nRigth[2]) * 2 + 1, 2) + '分';
end;
end;
Result:=lTemp + rTemp + '整';
end;
 
//来自以前的帖子
Function TForm33.CurrToCharNum(f:string):String;
var
Fs,dx,d2,zs,xs,h,jg:string;
i,ws,{l,}w,j,lx:integer;
begin
f := Trim(f);
if copy(f,1,1)='-' then begin
Delete(f,1,1);fs:='负';end
else fs:='';
dx:='零壹贰叁肆伍陆柒捌玖';
d2:='拾佰仟万亿';
i := AnsiPos('.',f); //小数点位置
if i = 0 Then
zs := f //整数
else begin
zs:=copy(f,1,i - 1); //整数部分
xs:=copy(f,i + 1,200);
end;
ws:= 0; //l := 0;
for i := Length(zs) downto 1 do begin
ws := ws + 1; h := '';
w:=strtoint(copy(zs, i, 1));
if (w=0) and (i=1) then jg:='零';
If w > 0 Then
Case ws of
2..5:h:=copy(d2,(ws-1)*2-1,2);
6..8:begin
h:=copy(d2,(ws-5)*2-1,2);
If AnsiPos('万',jg)=0 Then h:=h+'万';
end;
10..13:h := copy(d2,(ws-9)*2-1, 2);
End;
jg:=copy(dx,(w+1)*2-1,2) + h + jg;
If ws=9 Then jg := copy(jg,1,2) + '亿' + copy(jg,3,200);
end;
j:=AnsiPos('零零',jg);
While j > 0 do begin
jg := copy(jg, 1, j - 1) + copy(jg, j + 2,200);
j := AnsiPos('零零',jg);
end;
If (Length(jg) > 1) And (copy(jg,length(jg)-1,2)='零') Then jg :=copy(jg,1,Length(jg)-2);
j := AnsiPos('零亿',jg);
If j > 0 Then jg := copy(jg,1, j - 1) + copy(jg, j + 2,200);
//转换小数部分
lx := Length(xs);
If lx > 0 Then begin
jg := jg + '元';
For i := 1 To lx do begin
if i=1 then begin
jg := jg + copy(dx, strtoint(copy(xs,i,1))*2 + 1, 2);
jg := jg +'角';
end;
if i=2 then begin
jg := jg + copy(dx, strtoint(copy(xs,i,1))*2 + 1, 2);
jg := jg +'分';
end;
end;
j :=AnsiPos('零角零分',jg);
if j>0 then jg := copy(jg,1,j-1)+copy(jg,j+8,200)+'整';
j := AnsiPos('零角',jg);
i:=AnsiPos('零分',jg);
if (j>0) and (i>0) then jg := copy(jg,1,j-1)+copy(jg,j+4,200)
else begin
if (j>0)and(i=0) then jg:= copy(jg,1,j+1)+copy(jg,j+4,200);
if i>0 then jg := copy(jg,1,i-1);
end;
End
else
jg := jg + '元整';
result := fs+jg;

End;
 
用select case就可以解决的。
 
function TOBig(small: real): string;
var
SmallMonth, BigMonth: string;
wei1, qianwei1: string[2];
qianwei, dianweizhi, qian: integer;
begin
{------- 修改参数令值更精确 -------}
qianwei := -2; {小数点后的位置,需要的话也可以改动-2值}
Smallmonth := formatfloat('0.00', small); {转换成货币形式,需要的话小数点后加多几个零}
{---------------------------------}
dianweizhi := pos('.', Smallmonth); {小数点的位置}
for qian := length(Smallmonth) downto 1 do {循环小写货币的每一位,从小写的右边位置到左边}
begin
if qian <> dianweizhi then {如果读到的不是小数点就继续}
begin
case strtoint(copy(Smallmonth, qian, 1)) of {位置上的数转换成大写}
1: wei1 := '壹'; 2: wei1 := '贰';
3: wei1 := '叁'; 4: wei1 := '肆';
5: wei1 := '伍'; 6: wei1 := '陆';
7: wei1 := '柒'; 8: wei1 := '捌';
9: wei1 := '玖'; 0: wei1 := '零';
end;
case qianwei of {判断大写位置,可以继续增大到real类型的最大值}
- 3: qianwei1 := '厘';
- 2: qianwei1 := '分';
- 1: qianwei1 := '角';
0: qianwei1 := '元';
1: qianwei1 := '拾';
2: qianwei1 := '佰';
3: qianwei1 := '千';
4: qianwei1 := '万';
5: qianwei1 := '拾';
6: qianwei1 := '佰';
7: qianwei1 := '千';
8: qianwei1 := '亿';
9: qianwei1 := '十';
10: qianwei1 := '佰';
11: qianwei1 := '千';
end;
inc(qianwei);
BigMonth := wei1 + qianwei1 + BigMonth; {组合成大写金额}
end;
end;
result := BigMonth;
end;

 
这样的例子很多的,初步看了一下,上面的回答应该能够解决你的问题!
 
all
老大们,求你们试一试再贴,
用0.19试一下就知道了,结果是 “元壹角玖分”,那个“元”字不该有哇!!大家再想些注意吧!!!!
 
試試:
Function TMainForm.Changle(str:string):string;
Var Math1,unit1,math2:string;
i,count,j:integer;
mat1,mat2,mat3:string;
result1,result2,result3:string;
Begin
Try
if str='' then
result:=''
else
begin
mat1:=Formatfloat('0.000',strtofloat(str));
result1:='';
for i:=length(mat1) downto 1 do
begin
if mat1<>'.' then
begin
case mat1 of
'0':math1:='零';
'1':math1:='一';
'2':math1:='二';
'3':math1:='三';
'4':math1:='四';
'5':math1:='五';
'6':math1:='六';
'7':math1:='七';
'8':math1:='八';
'9':math1:='九';
end;

j:=length(mat1)-i+1;
case j of
1:unit1:='厘';
2:unit1:='分';
3:unit1:='角';
5:unit1:='元';
6:unit1:='十';
7:unit1:='百';
8:unit1:='千';
9:unit1:='萬';
10:unit1:='十';
11:unit1:='百';
12:unit1:='千';
13:unit1:='億';
14:unit1:='十';
15:unit1:='百';
16:unit1:='千';
17:unit1:='萬';
end;

result1:=math1+unit1+result1;
end;
end;
//元,萬,億前為零,將零刪除掉
//零后的除元,萬,億外的單位,將單位刪除掉
//不能連續出現兩個零
mat2:='元萬億';


while pos('零厘',result1)>0 do
delete(result1,pos('零厘',result1)+2,2);
while pos('零分',result1)>0 do
delete(result1,pos('零分',result1)+2,2);
while pos('零角',result1)>0 do
delete(result1,pos('零角',result1)+2,2);
while pos('零十',result1)>0 do
delete(result1,pos('零十',result1)+2,2);
while pos('零百',result1)>0 do
delete(result1,pos('零百',result1)+2,2);
while pos('零千',result1)>0 do
delete(result1,pos('零千',result1)+2,2);
while pos('零零',result1)>0 do
delete(result1,pos('零零',result1)+2,2);

while pos('零元',result1)>0 do
delete(result1,pos('零元',result1),2);
while pos('零萬',result1)>0 do
delete(result1,pos('零萬',result1),2);
while pos('零億',result1)>0 do
delete(result1,pos('零億',result1),2);
if copy(result1,1,2)='元' then
delete(result1,1,2);

if copy(result1,1,4)='一十' then
delete(result1,1,2);
while pos('億萬',result1)>0 do
delete(result1,pos('億萬',result1)+2,2);
if copy(result1,length(result1)-1,2)='零' then
delete(result1,length(result1)-1,2);
result:=result1;
end;

Except
showmessage('格式錯誤!');
abort;
End;

End;
 
一、DecimalToChinese(Number:extended;Cntype:integer):string;
<数字转换汉字大写的函数一>
<参数介绍>:Number:源数字,Extended类型
CnType:选择转换方式---0:转换为人民币大写
1:转换为汉字读法拼写
例如:decimaltocn(45092034.541,0)='肆仟伍佰零玖万贰仟零叁拾肆元伍角肆分
decimaltocn(45092034.541,1)='肆仟伍佰零玖万贰仟零叁拾肆点伍肆壹
注意:Number参数位数限制为15位,主要是受FloatTostr函数的限制。
如果大家有更好的方法请告诉我!


{***********************数字转换汉字函数A定义***********************}
function TTestForm.DecimalToChinese(number:Extended;cntype:integer):string;
{介绍:参数number为Extended类型
cntype=0:转换为人民币大写格式
cntype=1:转化为数字大写格式
例如:decimaltocn(45092034.541,0) :'肆仟伍佰零玖万贰仟零叁拾肆元伍角肆分
decimaltocn(45092034.541,1) :'肆仟伍佰零玖万贰仟零叁拾肆点伍肆壹
数值大小有限制,最大到百万亿 }
var
numstr:array[1..12] of string;//中文数位名
str1,str2,intstr,decstr:string;//整数部分,小数部分,大写整数部分,大写小数部分
num:array[1..10] of string;//各个数位段,即每四位为一段
n:array[1..10] of string;//各位数字
number1,number2,number3:string;//定义数字的三个数位段
pointpos:integer;//小数点位置
decpos:integer;
NumHead:string;//正负性
NumberName:string;//用于代替参数Number的字符串
NumLen:integer;//参数Number的串长度
begin
if (Cntype<>0) and (CnType<>1) then begin
showmessage('参数错误:选择转换类型参数值错误!');
result:='';
exit;
end;
{初始化}
numstr[1] :='零';
numstr[2] :='壹';
numstr[3] :='贰';
numstr[4] :='叁';
numstr[5] :='肆';
numstr[6] :='伍';
numstr[7] :='陆';
numstr[8] :='柒';
numstr[9] :='捌';
numstr[10]:='玖';
numstr[11]:='拾';
str1:='';
str2:='';
intstr:='';
decstr:='';
if Number<0 then//如果是负数,则在前面加‘负'
begin
NumHead:='负';
Number:=-Number;
end
else
NumHead:='';
NumberName:=Floattostr(Number);
NumLen:=Length(NumberName);
pointpos:=pos('.',NumberName);
//以下将得到整数部分Str1和小数部分Str2
if pointpos=0 then//输入值为纯整数
begin
str1:=NumberName;
str2:=''
end
else//输入值为浮点数
begin
if cntype=0 then//如果转换为人民币大写,并且小数数位超过2位,则只保留2位
if (NumLen-pos('.',numberName))>2 then NumberName:=trim(format('%'+inttostr(NumLen)+'.2f',[Number]));
str1:=copy(numberName,1,pos('.',numberName)-1);//取整数部分
str2:=copy(numberName,pos('.',numberName)+1,length(numberName)-pos('.',numberName));//取小数部分
if strtoint64(str2)=0 then //如果小数部分为0,则取消小数部分的分析
str2:='';
end;
{*****分析转换整数部分*****}
{分析整数部分在100000000以上的}
if length(str1)>8 then
begin
//按每4位为一段拆分成三段,逐段分析
num[1]:=copy(str1,1,length(str1)-8);//取8位以上的那部分数段
num[2]:=copy(str1,length(str1)-7,4);//取千万到万的4位
num[3]:=copy(str1,length(str1)-3,4);//取千到个位的4位
number1:=DecimalToChinese(strtoint64(num[1]),1)+'亿';//通过函数嵌套调用,得到亿上的数段格式,即若干亿

if strtoint64(Num[2])=0 then//如果千万到万4位为0
begin
if strtoint64(Num[3])=0 then//并且末尾4位为0
Number2:=''//没有内容
else
begin
if strtoint64(Num[3])<1000 then
Number2:=''//如果第三段也是零XX百十个,则中间段的"零"去掉
else
Number2:=numstr[1];//读零
end;
end
else
begin
if strtoint64(num[2])>1000 then //中间4位大于1000
Number2:=DecimalToChinese(strtoint64(num[2]),1)+'万'
else
Number2:=numStr[1]+DecimalToChinese(strtoint64(num[2]),1)+'万';//不足一千万,则读X亿零xx百、十、万
end;
if strtoint64(Num[3])=0 then//末尾4位为0
Number3:=''
else
begin
if strtoint64(num[3])>1000 then//末尾4位大于1000
Number3:=DecimalToChinese(strtoint64(num[3]),1)
else
Number3:=numstr[1]+DecimalToChinese(strtoint64(num[3]),1);//不足一千,则读X万零XX百、十
end;
intstr:=number1+number2+number3;
end;

{分析整数部分在10000~99999999之间的}
if (length(str1)>=5) and (length(str1)<=8) then
begin
num[1]:=copy(str1,1,length(str1)-4);//取得第一段(千万位到万位)
//为方便分析,若不足4位,用'0'补齐为4位
if length(num[1])=3 then
num[1]:='0'+num[1];
if length(num[1])=2 then
num[1]:='00'+num[1];
if length(num[1])=1 then
num[1]:='000'+num[1];
num[2]:=copy(str1,length(str1)-3,4);//取得第二段(千位到个位)
number1:=DecimalToChinese(strtoint64(num[1]),1)+'万';
if strtoint64(num[2])=0 then
number2:=''
else
begin
if strtoint64(num[2])>1000 then //中间4位大于1000
Number2:=DecimalToChinese(strtoint64(num[2]),1)
else
Number2:=numStr[1]+DecimalToChinese(strtoint64(num[2]),1);
end;
intstr:=number1+number2;
end;
{分析整数部分不到10000的}
if length(str1)<5 then
begin
num[1]:=str1;
//不足4位,用'0'补齐
if length(num[1])=3 then
num[1]:='0'+num[1];
if length(num[1])=2 then
num[1]:='00'+num[1];
if length(num[1])=1 then
num[1]:='000'+num[1];
number1:='';//亿以上的为空
number2:='';//万以上的为空
//分析千位
if copy(num[1],1,1)='0' then
n[1]:=''
else
n[1]:=numstr[strtoint64(copy(num[1],1,1))+1]+'仟';
//分析百位
if copy(num[1],2,1)='0' then
begin
if copy(num[1],1,1)='0' then
n[2]:=''
else
n[2]:=numstr[1]
end
else
n[2]:=numstr[strtoint64(copy(num[1],2,1))+1]+'佰';

//分析十位
if copy(num[1],3,1)='0' then
begin
if copy(num[1],2,1)='0' then
n[3]:=''
else
n[3]:=numstr[1]
end
else
begin
if (copy(num[1],1,1)='0') and (copy(num[1],2,1)='0') and (copy(num[1],3,1)='1') then//如果百位为0且十位为1则不读出壹字
n[3]:='拾'
else
n[3]:=numstr[strtoint64(copy(num[1],3,1))+1] +'拾';
end;

//分析个位
if copy(num[1],4,1)='0' then
n[4]:=''
else
n[4]:=numstr[strtoint64(copy(num[1],4,1))+1];

//
if copy(num[1],length(num[1])-2,3)='000' then//当末尾有000时
begin
n[2]:='';
n[3]:='';
n[4]:=''
end;
if copy(num[1],length(num[1])-1,2)='00' then//当末尾有00时
begin
n[3]:='';
n[4]:=''
end;
if copy(num[1],length(num[1]),1)='0' then//当末尾有0时
n[4]:='';
//数段合并
number3:=n[1]+n[2]+n[3]+n[4];
//取得整数位值
intstr:=number1+number2+number3;
end;
{如果整数为零,转换为"零"}
if str1='0' then
intstr:=numstr[1];

{整数转换完毕}


{*****分析和转换小数部分*****}
if length(str2)>0 then //如果小数数段不为空,则分析小数
begin
if cntype=0 then{一.如果转换为人民币表达式}
begin
//不足2位,用零补足空位
if length(str2)=1 then str2:=str2+'0';
if copy(str2,1,1)='0' then//角为0
begin
if Intstr='零' then n[1]:='' else n[1]:='零';//如果元为0,则不读0角,否则读零若干分
end
else
n[1]:=numstr[strtoint64(copy(str2,1,1))+1]+'角';
if copy(str2,2,1)='0' then
n[2]:=''
else
n[2]:=numstr[strtoint64(copy(str2,2,1))+1]+'分';
decstr:=n[1]+n[2];
end
else //二.如果转换为数字表达式
begin
decstr:='';
for decpos:=1 to length(str2) do
begin
decstr:=decstr+numstr[strtoint64(copy(str2,decpos,1))+1];
end;
end;
end;
{小数转换完毕}
{输出本函数的结果***********************}
if cntype=0 then//将数字字串转换为人民币的大写格式
begin
if str2='' then//如果为纯整数
result:=NumHead+intstr+'元整'
else
begin
if intstr='零' then//如果整数为零,就只显示小数
result:=NumHead+decstr
else
result:=NumHead+intstr+'元'+decstr
end;
end;
if cntype=1 then//将数字字串转换为普通大写格式
begin
if str2='' then//如果为纯整数
result:=NumHead+intstr
else
result:=NumHead+intstr+'点'+decstr
end;
{转换完毕}
end;

二、DecimalToChineseExt(Number:string;Cntype:integer):string;
<数字转换汉字大写的函数二>
<参数介绍>:Number:源数字,String类型
CnType:同上;
注意:本函数为上函数的变形,参数number无位数限制,但是在转换为
人民币大写的时候,参数Number小数位数不能超过2位!
(因为对太长的字符串不能转换成数字,不能进行四舍五入,索性加了限制)
{***********************数字转换汉字函数B定义***********************}
function TTestForm.DecimalToChineseExt(number:string;cntype:integer):string;
{介绍:参数number为string类型,数字格式
cntype=0:转换为人民币大写格式
cntype=1:转化为数字大写格式
例如:decimaltocn('45092034.54',0) :'肆仟伍佰零玖万贰仟零叁拾肆元伍角肆分
decimaltocn('45092034.54',1) :'肆仟伍佰零玖万贰仟零叁拾肆点伍肆
当转换为人民币大写时,number的小数位数不能超过2位!!}
var
numstr:array[1..12] of string;//中文数位名
str1,str2,intstr,decstr:string;//整数部分,小数部分,大写整数部分,大写小数部分
num:array[1..10] of string;//各个数位段,即每四位为一段
n:array[1..10] of string;//各位数字
number1,number2,number3:string;//定义数字的三个数位段
pointpos:integer;//小数点位置
decpos:integer;
NumHead:string;//正负性
NumLen:integer;//参数Number的串长度
begin
if (Cntype<>0) and (CnType<>1) then begin
showmessage('参数错误:选择转换类型参数值错误!');
result:='';
exit;
end;
{初始化}
numstr[1] :='零';
numstr[2] :='壹';
numstr[3] :='贰';
numstr[4] :='叁';
numstr[5] :='肆';
numstr[6] :='伍';
numstr[7] :='陆';
numstr[8] :='柒';
numstr[9] :='捌';
numstr[10]:='玖';
numstr[11]:='拾';
str1:='';
str2:='';
intstr:='';
decstr:='';
//若第一位有”-“号,则取出
NumHead:='';
if number[1]='-' then //可能是负数
begin
Number:=copy(Number,2,length(number)-1);
NumHead:='负';
end;
Numlen:=Length(number);//获得数字的长度
//先校验参数number是不是数字格式
//校验是否只有一个小数点
Decpos:=0;
for PointPos:=1 to Numlen do begin
if Number[PointPos]='.' then Decpos:=Decpos+1;
end;
if Decpos>1 then begin
showmessage('参数错误:不是数字格式!');
Result:='';
exit;
end;
//校验是否含有非数字和'.'的字母存在
for pointPos:=1 to Numlen do begin
if Number[pointpos]='.' then continue;
if (ord(Number[pointpos])<48) or (ord(Number[pointpos])>57) then begin
Result:='error';
break;
end;
end;
if Result='error' then begin
showmessage('参数错误:不是数字格式!');
result:='';
exit;
end;
//
pointpos:=pos('.',Number);//得到小数点的位置

//以下将得到整数部分Str1和小数部分Str2
if pointpos=0 then//输入值为纯整数
begin
str1:=Number;
str2:=''
end
else//输入值为浮点数
begin
str1:=copy(Number,1,PointPos-1);//取整数部分
str2:=copy(Number,PointPos+1,Numlen-PointPos);//取小数部分
//消除小数后面多余的0
while copy(str2,length(str2),1)='0' do
str2:=copy(str2,1,length(str2)-1);
if str2='' then str2:='0';
if cntype=0 then//如果转换为人民币大写,并且小数数位超过2位,则只保留2位
if length(str2)>2 then begin
showmessage('参数错误:转换为人民币时,小数位数最多是2位!');
result:='';
exit;
end;
end;
//消除整数部分前面的多余的0
while copy(str1,1,1)='0' do
str1:=copy(str1,2,length(str1)-1);
if str1='' then str1:='0';
{*****分析转换整数部分*****}
{分析整数部分在100000000以上的}
if length(str1)>8 then
begin
//按每4位为一段拆分成三段,逐段分析
num[1]:=copy(str1,1,length(str1)-8);//取8位以上的那部分数段
num[2]:=copy(str1,length(str1)-7,4);//取千万到万的4位
num[3]:=copy(str1,length(str1)-3,4);//取千到个位的4位
number1:=DecimalToChineseExt(num[1],1)+'亿';//通过函数嵌套调用,得到亿上的数段格式,即若干亿

if strtoint(Num[2])=0 then//如果千万到万4位为0
begin
if strtoint(Num[3])=0 then//并且末尾4位为0
Number2:=''//没有内容
else
begin
if strtoint(Num[3])<1000 then
Number2:=''//如果第三段也是零XX百十个,则中间段的"零"去掉
else
Number2:=numstr[1];//读零
end;
end
else
begin
if strtoint(num[2])>1000 then //中间4位大于1000
Number2:=DecimalToChineseExt(num[2],1)+'万'
else
Number2:=numStr[1]+DecimalToChineseExt(num[2],1)+'万';//不足一千万,则读X亿零xx百、十、万
end;
if strtoint(Num[3])=0 then//末尾4位为0
Number3:=''
else
begin
if strtoint(num[3])>1000 then//末尾4位大于1000
Number3:=DecimalToChineseExt(num[3],1)
else
Number3:=numstr[1]+DecimalToChineseExt(num[3],1);//不足一千,则读X万零XX百、十
end;
intstr:=number1+number2+number3;
end;

{分析整数部分在10000~99999999之间的}
if (length(str1)>=5) and (length(str1)<=8) then
begin
num[1]:=copy(str1,1,length(str1)-4);//取得第一段(千万位到万位)
//为方便分析,若不足4位,用'0'补齐为4位
if length(num[1])=3 then
num[1]:='0'+num[1];
if length(num[1])=2 then
num[1]:='00'+num[1];
if length(num[1])=1 then
num[1]:='000'+num[1];
num[2]:=copy(str1,length(str1)-3,4);//取得第二段(千位到个位)
number1:=DecimalToChineseExt(num[1],1)+'万';
if strtoint(num[2])=0 then
number2:=''
else
begin
if strtoint(num[2])>1000 then //中间4位大于1000
Number2:=DecimalToChineseExt(num[2],1)
else
Number2:=numStr[1]+DecimalToChineseExt(num[2],1);
end;
intstr:=number1+number2;
end;
{分析整数部分不到10000的}
if length(str1)<5 then
begin
num[1]:=str1;
//不足4位,用'0'补齐
if length(num[1])=3 then
num[1]:='0'+num[1];
if length(num[1])=2 then
num[1]:='00'+num[1];
if length(num[1])=1 then
num[1]:='000'+num[1];
number1:='';//亿以上的为空
number2:='';//万以上的为空
//分析千位
if copy(num[1],1,1)='0' then
n[1]:=''
else
n[1]:=numstr[strtoint(copy(num[1],1,1))+1]+'仟';
//分析百位
if copy(num[1],2,1)='0' then
begin
if copy(num[1],1,1)='0' then
n[2]:=''
else
n[2]:=numstr[1]
end
else
n[2]:=numstr[strtoint(copy(num[1],2,1))+1]+'佰';

//分析十位
if copy(num[1],3,1)='0' then
begin
if copy(num[1],2,1)='0' then
n[3]:=''
else
n[3]:=numstr[1]
end
else
begin
if (copy(num[1],1,1)='0') and (copy(num[1],2,1)='0') and (copy(num[1],3,1)='1') then//如果百位为0且十位为1则不读出壹字
n[3]:='拾'
else
n[3]:=numstr[strtoint(copy(num[1],3,1))+1] +'拾';
end;

//分析个位
if copy(num[1],4,1)='0' then
n[4]:=''
else
n[4]:=numstr[strtoint(copy(num[1],4,1))+1];

//
if copy(num[1],length(num[1])-2,3)='000' then//当末尾有000时
begin
n[2]:='';
n[3]:='';
n[4]:=''
end;
if copy(num[1],length(num[1])-1,2)='00' then//当末尾有00时
begin
n[3]:='';
n[4]:=''
end;
if copy(num[1],length(num[1]),1)='0' then//当末尾有0时
n[4]:='';
//数段合并
number3:=n[1]+n[2]+n[3]+n[4];
//取得整数位值
intstr:=number1+number2+number3;
end;
{如果整数为零,转换为"零"}
if str1='0' then
intstr:=numstr[1];

{整数转换完毕}


{*****分析和转换小数部分*****}
if length(str2)>0 then //如果小数数段不为空,则分析小数
begin
if cntype=0 then{一.如果转换为人民币表达式}
begin
//不足2位,用零补足空位
if length(str2)=1 then str2:=str2+'0';
if copy(str2,1,1)='0' then//角为0
begin
if Intstr='零' then n[1]:='' else n[1]:='零';//如果元为0,则不读0角,否则读零若干分
end
else
n[1]:=numstr[strtoint(copy(str2,1,1))+1]+'角';
if copy(str2,2,1)='0' then
n[2]:=''
else
n[2]:=numstr[strtoint(copy(str2,2,1))+1]+'分';
decstr:=n[1]+n[2];
end
else //二.如果转换为数字表达式
begin
decstr:='';
for decpos:=1 to length(str2) do
begin
decstr:=decstr+numstr[strtoint(copy(str2,decpos,1))+1];
end;
end;
end;
{小数转换完毕}
{输出本函数的结果***********************}
if cntype=0 then//将数字字串转换为人民币的大写格式
begin
if str2='' then//如果为纯整数
result:=NumHead+intstr+'元整'
else
begin
if intstr='零' then//如果整数为零,就只显示小数
result:=NumHead+decstr
else
result:=NumHead+intstr+'元'+decstr
end;
end;
if cntype=1 then//将数字字串转换为普通大写格式
begin
if str2='' then//如果为纯整数
result:=NumHead+intstr
else
result:=NumHead+intstr+'点'+decstr
end;
{转换完毕}
end;


以上是我考来的,一下是我自己在VFP中写的:
{***********************数字转换汉字函数B定义***********************}
function TTestForm.DecimalToChineseExt(number:string;cntype:integer):string;
{介绍:参数number为string类型,数字格式
cntype=0:转换为人民币大写格式
cntype=1:转化为数字大写格式
例如:decimaltocn('45092034.54',0) :'肆仟伍佰零玖万贰仟零叁拾肆元伍角肆分
decimaltocn('45092034.54',1) :'肆仟伍佰零玖万贰仟零叁拾肆点伍肆
当转换为人民币大写时,number的小数位数不能超过2位!!}
var
numstr:array[1..12] of string;//中文数位名
str1,str2,intstr,decstr:string;//整数部分,小数部分,大写整数部分,大写小数部分
num:array[1..10] of string;//各个数位段,即每四位为一段
n:array[1..10] of string;//各位数字
number1,number2,number3:string;//定义数字的三个数位段
pointpos:integer;//小数点位置
decpos:integer;
NumHead:string;//正负性
NumLen:integer;//参数Number的串长度
begin
if (Cntype<>0) and (CnType<>1) then begin
showmessage('参数错误:选择转换类型参数值错误!');
result:='';
exit;
end;
{初始化}
numstr[1] :='零';
numstr[2] :='壹';
numstr[3] :='贰';
numstr[4] :='叁';
numstr[5] :='肆';
numstr[6] :='伍';
numstr[7] :='陆';
numstr[8] :='柒';
numstr[9] :='捌';
numstr[10]:='玖';
numstr[11]:='拾';
str1:='';
str2:='';
intstr:='';
decstr:='';
//若第一位有”-“号,则取出
NumHead:='';
if number[1]='-' then //可能是负数
begin
Number:=copy(Number,2,length(number)-1);
NumHead:='负';
end;
Numlen:=Length(number);//获得数字的长度
//先校验参数number是不是数字格式
//校验是否只有一个小数点
Decpos:=0;
for PointPos:=1 to Numlen do begin
if Number[PointPos]='.' then Decpos:=Decpos+1;
end;
if Decpos>1 then begin
showmessage('参数错误:不是数字格式!');
Result:='';
exit;
end;
//校验是否含有非数字和'.'的字母存在
for pointPos:=1 to Numlen do begin
if Number[pointpos]='.' then continue;
if (ord(Number[pointpos])<48) or (ord(Number[pointpos])>57) then begin
Result:='error';
break;
end;
end;
if Result='error' then begin
showmessage('参数错误:不是数字格式!');
result:='';
exit;
end;
//
pointpos:=pos('.',Number);//得到小数点的位置

//以下将得到整数部分Str1和小数部分Str2
if pointpos=0 then//输入值为纯整数
begin
str1:=Number;
str2:=''
end
else//输入值为浮点数
begin
str1:=copy(Number,1,PointPos-1);//取整数部分
str2:=copy(Number,PointPos+1,Numlen-PointPos);//取小数部分
//消除小数后面多余的0
while copy(str2,length(str2),1)='0' do
str2:=copy(str2,1,length(str2)-1);
if str2='' then str2:='0';
if cntype=0 then//如果转换为人民币大写,并且小数数位超过2位,则只保留2位
if length(str2)>2 then begin
showmessage('参数错误:转换为人民币时,小数位数最多是2位!');
result:='';
exit;
end;
end;
//消除整数部分前面的多余的0
while copy(str1,1,1)='0' do
str1:=copy(str1,2,length(str1)-1);
if str1='' then str1:='0';
{*****分析转换整数部分*****}
{分析整数部分在100000000以上的}
if length(str1)>8 then
begin
//按每4位为一段拆分成三段,逐段分析
num[1]:=copy(str1,1,length(str1)-8);//取8位以上的那部分数段
num[2]:=copy(str1,length(str1)-7,4);//取千万到万的4位
num[3]:=copy(str1,length(str1)-3,4);//取千到个位的4位
number1:=DecimalToChineseExt(num[1],1)+'亿';//通过函数嵌套调用,得到亿上的数段格式,即若干亿

if strtoint(Num[2])=0 then//如果千万到万4位为0
begin
if strtoint(Num[3])=0 then//并且末尾4位为0
Number2:=''//没有内容
else
begin
if strtoint(Num[3])<1000 then
Number2:=''//如果第三段也是零XX百十个,则中间段的"零"去掉
else
Number2:=numstr[1];//读零
end;
end
else
begin
if strtoint(num[2])>1000 then //中间4位大于1000
Number2:=DecimalToChineseExt(num[2],1)+'万'
else
Number2:=numStr[1]+DecimalToChineseExt(num[2],1)+'万';//不足一千万,则读X亿零xx百、十、万
end;
if strtoint(Num[3])=0 then//末尾4位为0
Number3:=''
else
begin
if strtoint(num[3])>1000 then//末尾4位大于1000
Number3:=DecimalToChineseExt(num[3],1)
else
Number3:=numstr[1]+DecimalToChineseExt(num[3],1);//不足一千,则读X万零XX百、十
end;
intstr:=number1+number2+number3;
end;

{分析整数部分在10000~99999999之间的}
if (length(str1)>=5) and (length(str1)<=8) then
begin
num[1]:=copy(str1,1,length(str1)-4);//取得第一段(千万位到万位)
//为方便分析,若不足4位,用'0'补齐为4位
if length(num[1])=3 then
num[1]:='0'+num[1];
if length(num[1])=2 then
num[1]:='00'+num[1];
if length(num[1])=1 then
num[1]:='000'+num[1];
num[2]:=copy(str1,length(str1)-3,4);//取得第二段(千位到个位)
number1:=DecimalToChineseExt(num[1],1)+'万';
if strtoint(num[2])=0 then
number2:=''
else
begin
if strtoint(num[2])>1000 then //中间4位大于1000
Number2:=DecimalToChineseExt(num[2],1)
else
Number2:=numStr[1]+DecimalToChineseExt(num[2],1);
end;
intstr:=number1+number2;
end;
{分析整数部分不到10000的}
if length(str1)<5 then
begin
num[1]:=str1;
//不足4位,用'0'补齐
if length(num[1])=3 then
num[1]:='0'+num[1];
if length(num[1])=2 then
num[1]:='00'+num[1];
if length(num[1])=1 then
num[1]:='000'+num[1];
number1:='';//亿以上的为空
number2:='';//万以上的为空
//分析千位
if copy(num[1],1,1)='0' then
n[1]:=''
else
n[1]:=numstr[strtoint(copy(num[1],1,1))+1]+'仟';
//分析百位
if copy(num[1],2,1)='0' then
begin
if copy(num[1],1,1)='0' then
n[2]:=''
else
n[2]:=numstr[1]
end
else
n[2]:=numstr[strtoint(copy(num[1],2,1))+1]+'佰';

//分析十位
if copy(num[1],3,1)='0' then
begin
if copy(num[1],2,1)='0' then
n[3]:=''
else
n[3]:=numstr[1]
end
else
begin
if (copy(num[1],1,1)='0') and (copy(num[1],2,1)='0') and (copy(num[1],3,1)='1') then//如果百位为0且十位为1则不读出壹字
n[3]:='拾'
else
n[3]:=numstr[strtoint(copy(num[1],3,1))+1] +'拾';
end;

//分析个位
if copy(num[1],4,1)='0' then
n[4]:=''
else
n[4]:=numstr[strtoint(copy(num[1],4,1))+1];

//
if copy(num[1],length(num[1])-2,3)='000' then//当末尾有000时
begin
n[2]:='';
n[3]:='';
n[4]:=''
end;
if copy(num[1],length(num[1])-1,2)='00' then//当末尾有00时
begin
n[3]:='';
n[4]:=''
end;
if copy(num[1],length(num[1]),1)='0' then//当末尾有0时
n[4]:='';
//数段合并
number3:=n[1]+n[2]+n[3]+n[4];
//取得整数位值
intstr:=number1+number2+number3;
end;
{如果整数为零,转换为"零"}
if str1='0' then
intstr:=numstr[1];

{整数转换完毕}


{*****分析和转换小数部分*****}
if length(str2)>0 then //如果小数数段不为空,则分析小数
begin
if cntype=0 then{一.如果转换为人民币表达式}
begin
//不足2位,用零补足空位
if length(str2)=1 then str2:=str2+'0';
if copy(str2,1,1)='0' then//角为0
begin
if Intstr='零' then n[1]:='' else n[1]:='零';//如果元为0,则不读0角,否则读零若干分
end
else
n[1]:=numstr[strtoint(copy(str2,1,1))+1]+'角';
if copy(str2,2,1)='0' then
n[2]:=''
else
n[2]:=numstr[strtoint(copy(str2,2,1))+1]+'分';
decstr:=n[1]+n[2];
end
else //二.如果转换为数字表达式
begin
decstr:='';
for decpos:=1 to length(str2) do
begin
decstr:=decstr+numstr[strtoint(copy(str2,decpos,1))+1];
end;
end;
end;
{小数转换完毕}
{输出本函数的结果***********************}
if cntype=0 then//将数字字串转换为人民币的大写格式
begin
if str2='' then//如果为纯整数
result:=NumHead+intstr+'元整'
else
begin
if intstr='零' then//如果整数为零,就只显示小数
result:=NumHead+decstr
else
result:=NumHead+intstr+'元'+decstr
end;
end;
if cntype=1 then//将数字字串转换为普通大写格式
begin
if str2='' then//如果为纯整数
result:=NumHead+intstr
else
result:=NumHead+intstr+'点'+decstr
end;
{转换完毕}
end;

 
我自己的考错了,不过以上两个够用了吧
 
函数+例子:
(转贴)

///////Begin Source

{把阿拉伯数字转换成大写数字}

function NumberCn(mNumber: Real): WideString;
const
cPointCn: WideString = '点十百千万十百千亿十百千';
cNumberCn: WideString = '零一二三四五六七八九';
var
I, L, P: Integer;
S: string;
begin
Result := '';
if mNumber = 0 then begin
Result := cNumberCn[1];
Exit;
end;
S := FloatToStr(mNumber);
if Pos('.', S) <= 0 then S := S + '.';
P := Pos('.', S);
L := Length(S);
for I := 1 to L do
if P > I then
Result := Result + cNumberCn[StrToInt(S) + 1] + cPointCn[P - I]
else if P = I then begin
Result := StringReplace(Result, '零十零', '零', [rfReplaceAll]);
Result := StringReplace(Result, '零百零', '零', [rfReplaceAll]);
Result := StringReplace(Result, '零千零', '零', [rfReplaceAll]);
Result := StringReplace(Result, '零十', '零', [rfReplaceAll]);
Result := StringReplace(Result, '零百', '零', [rfReplaceAll]);
Result := StringReplace(Result, '零千', '零', [rfReplaceAll]);
Result := StringReplace(Result, '零万', '万', [rfReplaceAll]);
Result := StringReplace(Result, '零亿', '亿', [rfReplaceAll]);
Result := StringReplace(Result, '亿万', '亿', [rfReplaceAll]);
Result := StringReplace(Result, '零点', '点', [rfReplaceAll]);
end else if P < I then
Result := Result + cNumberCn[StrToInt(S) + 1];
if Result[Length(Result)] = cPointCn[1] then
Result := Copy(Result, 1, Length(Result) - 1);
if Result[1] = cPointCn[1] then Result := cNumberCn[1] + Result;
if (Length(Result) > 1) and (Result[2] = cPointCn[2]) and
(Result[1] = cNumberCn[2]) then
Delete(Result, 1, 1);
end; { NumberCn }

{把阿拉伯数字转换成人民币汉字}
function MoneyCn(mMoney: Real): WideString;
var
P: Integer;
begin
if mMoney = 0 then begin
Result := '无';
Exit;
end;
Result := NumberCn(Round(mMoney * 100) / 100);
Result := StringReplace(Result, '一', '壹', [rfReplaceAll]);
Result := StringReplace(Result, '二', '贰', [rfReplaceAll]);
Result := StringReplace(Result, '三', '叁', [rfReplaceAll]);
Result := StringReplace(Result, '四', '肆', [rfReplaceAll]);
Result := StringReplace(Result, '五', '伍', [rfReplaceAll]);
Result := StringReplace(Result, '六', '陆', [rfReplaceAll]);
Result := StringReplace(Result, '七', '柒', [rfReplaceAll]);
Result := StringReplace(Result, '八', '捌', [rfReplaceAll]);
Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
Result := StringReplace(Result, '十', '拾', [rfReplaceAll]);
Result := StringReplace(Result, '百', '佰', [rfReplaceAll]);
Result := StringReplace(Result, '千', '仟', [rfReplaceAll]);
P := Pos('点', Result);
if P > 0 then begin
Insert('分', Result, P + 3);
Insert('角', Result, P + 2);
Result := StringReplace(Result, '点', '圆', [rfReplaceAll]);
Result := StringReplace(Result, '角分', '角', [rfReplaceAll]);
Result := StringReplace(Result, '零分', '', [rfReplaceAll]);
Result := StringReplace(Result, '零角', '', [rfReplaceAll]);
Result := StringReplace(Result, '分角', '', [rfReplaceAll]);
if Copy(Result, 1, 2) = '零圆' then
Result := StringReplace(Result, '零圆', '', [rfReplaceAll]);
end else Result := Result + '圆整';
Result := '人民币' + Result;
end; { MoneyCn }
///////End Source

///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := MoneyCn(StrToFloatDef(Edit3.Text, 0));
Edit2.Text := NumberCn(StrToFloatDef(Edit3.Text, 0));
end;
///////End Demo
 
多人接受答案了。
 
顶部