delphi人民币大小写转换.docx
- 文档编号:25552076
- 上传时间:2023-06-09
- 格式:DOCX
- 页数:37
- 大小:22.07KB
delphi人民币大小写转换.docx
《delphi人民币大小写转换.docx》由会员分享,可在线阅读,更多相关《delphi人民币大小写转换.docx(37页珍藏版)》请在冰豆网上搜索。
delphi人民币大小写转换
Delphi人民币大小写转换
Delphi人民币大小写转换
时间:
2011-5-24来源:
yang作者:
peng点击:
745次
functionTPrintfrm.NumToChar(n:
Real):
wideString;//可以到万亿,并可随便扩大
const
cNum:
WideString=‘零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分‘;
cCha:
array[0..1,0..11]ofstring=
((‘零仟‘,‘零佰‘,‘零拾‘,‘零零零‘,‘零零‘,
‘零亿‘,‘零万‘,‘零元‘,‘亿万‘,‘零角‘,‘零分‘,‘零整‘),
(‘零‘,‘零‘,‘零‘,‘零‘,‘零‘,‘亿‘,‘万‘,‘元‘,‘亿‘,‘零‘,‘整‘,‘整‘));
var
i:
Integer;
sNum:
WideString;
begin
Result:
=‘‘;
//n:
=Round(n*10)/10;
//FormatFloat(‘0.0‘,)
sNum:
=FormatFloat(‘0‘,n*100);
fori:
=1toLength(sNum)do
Result:
=Result+cNum[ord(sNum[i])-47]+cNum[26-Length(sNum)+i];
fori:
=0to11do//去掉多余的零
Result:
=StringReplace(result,cCha[0,i],cCha[1,i],[rfReplaceAll]);
end;
2009-7-2314:
12:
10第二种方法
functionTSnnofrm.LowToUpcase(xx:
Real):
string;
var
i:
Integer;
j,dxhj:
string;
zero:
boolean;
begin
j:
=FormatFloat(‘0.0‘,xx);
j:
=Trim(IntToStr(Round(xx*100)));
ifpos(‘.‘,j)<>0then
j:
=Copy(j,1,pos(‘.‘,j)-1);
ifj=‘‘then
j:
=‘0‘;
ifcopy(j,length(j),1)=‘0‘then
begin
dxhj:
=‘整‘;
zero:
=True;
end
else
begin
dxhj:
=‘‘;
zero:
=False;
end;fori:
=0toLength(j)-1do
begin
ifStrToInt(Copy(j,Length(j)-i,1))<>0then
caseiof
0:
dxhj:
=‘分‘+dxhj;
1:
dxhj:
=‘角‘+dxhj;
2:
dxhj:
=‘元‘+dxhj;
3:
dxhj:
=‘拾‘+dxhj;
4:
dxhj:
=‘佰‘+dxhj;
5:
dxhj:
=‘仟‘+dxhj;
6:
dxhj:
=‘万‘+dxhj;
7:
dxhj:
=‘拾‘+dxhj;
8:
dxhj:
=‘佰‘+dxhj;
9:
dxhj:
=‘仟‘+dxhj;
10:
dxhj:
=‘亿‘+dxhj;
11:
dxhj:
=‘拾‘+dxhj;
end;caseStrToInt(Copy(j,Length(j)-i,1))of
0:
begin
ifnotzerothen
dxhj:
=‘零‘+dxhj;
zero:
=True;
end;
1:
begin
dxhj:
=‘壹‘+dxhj;
zero:
=False;
end;
2:
begin
dxhj:
=‘贰‘+dxhj;
zero:
=False;
end;
3:
begin
dxhj:
=‘叁‘+dxhj;
zero:
=False;
end;
4:
begin
dxhj:
=‘肆‘+dxhj;
zero:
=False;
end;
5:
begin
dxhj:
=‘五‘+dxhj;
zero:
=False;
end;
6:
begin
dxhj:
=‘六‘+dxhj;
zero:
=False;
end;
7:
begin
dxhj:
=‘七‘+dxhj;
zero:
=False;
end;
8:
begin
dxhj:
=‘八‘+dxhj;
zero:
=False;
end;
9:
begin
dxhj:
=‘玖‘+dxhj;
zero:
=False;
end;
end;
end;
ifdxhj=‘整‘then
dxhj:
=‘‘;
Result:
=dxhj;
end;
2009-7-2314:
12:
54第三种方法
functionNumberCn(mNumber:
Real):
WideString;
const
cPointCn:
WideString=‘点十百千万十百千亿十百千‘;
cNumberCn:
WideString=‘零一二三四五六七八九‘;
var
I,L,P:
Integer;
S:
string;
begin
Result:
=‘‘;
ifmNumber=0thenbegin
Result:
=cNumberCn[1];
Exit;
end;
S:
=FloatToStr(mNumber);
ifPos(‘.‘,S)<=0thenS:
=S+‘.‘;
P:
=Pos(‘.‘,S);
L:
=Length(S);
forI:
=1toLdo
ifP>Ithen
Result:
=Result+cNumberCn[StrToInt(S[I])+1]+cPointCn[P-I]
elseifP=Ithenbegin
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]);
endelseifP<Ithen
Result:
=Result+cNumberCn[StrToInt(S[I])+1];
ifResult[Length(Result)]=cPointCn[1]then
Result:
=Copy(Result,1,Length(Result)-1);
ifResult[1]=cPointCn[1]thenResult:
=cNumberCn[1]+Result;
if(Length(Result)>1)and(Result[2]=cPointCn[2])and
(Result[1]=cNumberCn[2])then
Delete(Result,1,1);
end;{NumberCn}
functionMoneyCn(mMoney:
Real):
WideString;
var
P:
Integer;
begin
ifmMoney=0thenbegin
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);
ifP>0thenbegin
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]);
ifCopy(Result,1,2)=‘零圆‘then
Result:
=StringReplace(Result,‘零圆‘,‘‘,[rfReplaceAll]);
endelseResult:
=Result+‘圆整‘;
Result:
=‘人民币‘+Result;
end;
2009-7-2314:
13:
36第四种方法
给你个函数吧
functionTjfdy.SmallTOBig(small:
real):
string;
var
SmallMonth,BigMonth:
string;
wei1,qianwei1:
string[2];
qianwei,dianweizhi,qian:
integer;
begin
{-------修改参数令值更精确-------}
{小数点后的位数,需要的话也可以改动该值}
qianwei:
=-2;
{转换成货币形式,需要的话小数点后加多几个零}
Smallmonth:
=formatfloat(‘0.00‘,small);
{---------------------------------}
dianweizhi:
=pos(‘.‘,Smallmonth);{小数点的位置}
{循环小写货币的每一位,从小写的右边位置到左边}
forqian:
=length(Smallmonth)downto1do
begin
{如果读到的不是小数点就继续}
ifqian<>dianweizhithen
begin
{位置上的数转换成大写}
casestrtoint(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;
{判断大写位置,可以继续增大到real类型的最大值,可是谁有那么多钱}
caseqianweiof
-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;
SmallTOBig:
=BigMonth;
end;
2009-7-2314:
14:
51第五种方法
FunctionTFormFhdCw.XxToDx(consthjnum:
real):
String;
varVstr,zzz,cc,cc1,Presult:
string;
xxbb:
array[1..12]ofstring;
uppna:
array[0..9]ofstring;
iCount,iZero,vPoint,vdtlno:
integer;
begin
//*设置大写中文数字和相应单位数组*//
xxbb[1]:
=‘亿‘;
xxbb[2]:
=‘仟‘;
xxbb[3]:
=‘佰‘;
xxbb[4]:
=‘拾‘;
xxbb[5]:
=‘万‘;
xxbb[6]:
=‘仟‘;
xxbb[7]:
=‘佰‘;
xxbb[8]:
=‘拾‘;
xxbb[9]:
=‘元‘;
xxbb[10]:
=‘.‘;
xxbb[11]:
=‘角‘;
xxbb[12]:
=‘分‘;
uppna[0]:
=‘零‘;
uppna[1]:
=‘壹‘;
uppna[2]:
=‘贰‘;
uppna[3]:
=‘叁‘;
uppna[4]:
=‘肆‘;
uppna[5]:
=‘伍‘;
uppna[6]:
=‘陆‘;
uppna[7]:
=‘柒‘;
uppna[8]:
=‘捌‘;
uppna[9]:
=‘玖‘;
Str(hjnum:
12:
2,Vstr);
cc:
=‘‘;
cc1:
=‘‘;
zzz:
=‘‘;
result:
=‘‘;
presult:
=‘‘;
iZero:
=0;
vPoint:
=0;
foriCount:
=1to10do
begin
cc:
=Vstr[iCount];
ifcc<>‘‘then
begin
zzz:
=xxbb[iCount];
ifcc=‘0‘then
begin
ifiZero<1then//*对“零”进行判断*//
cc:
=‘零‘
else
cc:
=‘‘;
ifiCount=5then//*对万位“零”的处理*//
ifcopy(result,length(result)-1,2)=‘零‘then
result:
=copy(result,1,length(result)-2)+xxbb[iCount]
+‘零‘
else
result:
=result+xxbb[iCount];
cc1:
=cc;
zzz:
=‘‘;
iZero:
=iZero+1;
end
else
begin
ifcc=‘.‘then
begin
cc:
=‘‘;
if(cc1=‘‘)or(cc1=‘零‘)then
begin
Presult:
=copy(result,1,Length(result)-2);
result:
=Presult;
iZero:
=15;
end;
ifiZero>=1then
zzz:
=xxbb[9]
else
zzz:
=‘‘;
vPoint:
=1;
end
else
begin
iZero:
=0;
cc:
=uppna[StrToInt(cc)];
end
end;
result:
=result+(cc+zzz)
end;
end;
IfVstr[11]=‘0‘then//*对小数点后两位进行处理*//
begin
ifVstr[12]<>‘0‘then
begin
cc:
=‘零‘;
result:
=result+cc;
cc:
=uppna[StrToInt(Vstr[12])];
result:
=result+(uppna[0]+cc+xxbb[12]);
end
end
else
begin
ifiZero=15then
begin
cc:
=‘零‘;
result:
=result+cc;
end;
cc:
=uppna[StrToInt(Vstr[11])];
result:
=result+(cc+xxbb[11]);
ifVstr[12]<>‘0‘then
begin
cc:
=uppna[StrToInt(Vstr[12])];
result:
=result+(cc+xxbb[12]);
end;
end;
result:
=result+‘正‘;
end;
2009-7-2314:
15:
36第六种方法
给你一段很短的代码吧,好用,我用过的
functionTForm1.xTOd(i:
Real):
string;
const
d=‘零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿‘;
var
m,k:
string;
j:
integer;
begin
k:
=‘‘;
m:
=floattostr(int(i*100));
forj:
=length(m)downto1do
k:
=k+d[(strtoint(m[Length(m)-j+1])+1)*2-1]+
d[(strtoint(m[Length(m)-j+1])+1)*2]+d[(10+j)*2-1]+d[(10+j)*2];
xTOd:
=k;
end;
调用:
procedureTForm1.Button1Click(Sender:
TObject);
var
Sum:
real;
begin
sum:
=12.34;
showmessage(‘人民币大写:
‘+xTOd(Sum));
end;
2009-7-2314:
16:
47第七种方法
functionSmallTOBig(small:
real):
string;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- delphi 人民币 大小写 转换