📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,idglobal;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button3: TButton;
Edit3: TEdit;
Button5: TButton;
Label1: TLabel;
Label2: TLabel;
Edit4: TEdit;
Label3: TLabel;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
function zifu(jey:variant):string;
function shuzi(jey:string):string;
function shuzi1(jey:string):string;
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin;
end;
function TForm1.zifu(jey:variant):string;
var
shuzi:string; //保存数字小写
l,i:integer; //l是数字长度,i是数字的位
shu:array of string[2]; //保存单位
shu1:array of string[2]; //保存数字大写字符
b:boolean; //条件参数
begin
if jey>99999999.99 then result:='error,数值太大!!' //数值只能在1亿里内,否则结果为'error!'
ELSE
begin
if jey<0.001 then //数值小于0.001则结果为零
begin
result:='零';
exit;
end;
SetLength(shu,10);SetLength(shu1,10); //设置长度
shu[9]:='仟'; shu[8]:='佰'; shu[7]:='拾';shu[6]:='万';shu[5]:='仟';
shu[4]:='佰'; shu[3]:='拾'; shu[2]:='元';shu[1]:='角';shu[0]:='分';
SHU1[0]:='零';SHU1[1]:='壹';SHU1[2]:='贰';SHU1[3]:='叁';SHU1[4]:='肆';
SHU1[5]:='伍';SHU1[6]:='陆';SHU1[7]:='柒';SHU1[8]:='捌';SHU1[9]:='玖';
shuzi:=vartostr(round(jey*100)); //将浮点型数字转换成字符型数字(保留二位小数)
b:=false;
l:=length(shuzi); //数值长度
i:=1;
result:='';
while i<=l do //计算每位结果
begin
if copy(shuzi,l-i+1,1)<>'0' then //位不为零时,则result:=大写+单位+小一位的结果
begin
result:=SHU1[STRTOINT(COPY(SHUZI,l-i+1,1))]+SHU[i-1]+result;
b:=true;
end
else if b=true then //位为零时,则result:='零'+小一位的结果
begin
result:='零'+result;
b:=false;
end;
if (i=6) and (i<l)and (copy(shuzi,l-6,1)='0') then //满足以上三个条件,则result:='万'+小一位的结果
begin
result:='万'+result; //万位
b:=false;
end;
if (i=2) and (i<l)and (copy(shuzi,l-2,1)='0') then //满足以上三个条件,则result:='元'+小一位的结果
begin
result:='元'+result; //个位
b:=false;
end;
i:=i+1;
end; //end-while
end; //end-if
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
edit3.Text:=zifu(edit1.Text)
end;
function TForm1.shuzi(jey: string):string ;
var
i:integer;
s,s1,s2:integer;
ab:integer;
a,b,s3,s4:string;
begin
i:=1; ab:=0; a:=''; b:='';s:=0;s1:=0;s2:=0;s3:='0';s4:='0';
while i<=length(jey) do
begin
ab:=strtoint(shuzi1(copy(jey,i,2)));
if ab=10000000 then
begin
b:=copy(jey,i+2,length(jey));
a:=copy(jey,1,i-1)+'元';
end;
i:=i+2;
end; //end-- while
if length(b)=0 then b:=jey;
i:=1;
while i<=length(b) do
begin
s1:=strtoint(shuzi1(copy(b,i,2)));
if s1 in [0..9] then
begin
s:=s1;
end
else
begin
s:=s1*s;
s3:=inttostr((s)+strtoint(s3));
s:=0;
end;
i:=i+2;
end; //end-- while 仟以下
i:=1;s:=0;s1:=0;s2:=0;
while i<=length(a) do
begin
s1:=strtoint(shuzi1(copy(a,i,2)));
if s1 in [0..9] then
begin
s:=s1;
end
else
begin
s:=s1*s;
s4:=inttostr((s)+strtoint(s4));
s:=0;
end;
i:=i+2;
end; //end-- while 万以上
if length(s4)>1 then
result:=inttostr(strtoint(copy(s4,1,length(s4)-3))*10000+(strtoint(s3)div 1000))
else
result:=inttostr(strtoint(s3)div 1000);
if strtoint(copy(s3,length(s3)-1,1))<>0 then
result:=result+'.'+copy(s3,length(s3)-2,2)
else if strtoint(copy(s3,length(s3)-2,1))<>0 then
result:=result+'.'+copy(s3,length(s3)-2,1);
end; //end-- begin
function TForm1.shuzi1(jey: string):string;
var
i:integer;
s:integer;
s1:string;
shu1:array of string[2];
begin
s1:='168';
i:=0;
SetLength(shu1,17);
shu1[16]:='万';shu1[15]:='仟';
shu1[14]:='佰'; shu1[13]:='拾'; shu1[12]:='元';shu1[11]:='角';shu1[10]:='分';
SHU1[0]:='零';SHU1[1]:='壹';SHU1[2]:='贰';SHU1[3]:='叁';SHU1[4]:='肆';
SHU1[5]:='伍';SHU1[6]:='陆';SHU1[7]:='柒';SHU1[8]:='捌';SHU1[9]:='玖';
for i:=0 to 16 do
begin
if jey<>shu1[i] then continue;
s:=i;
break;
end;
case s of
0:s1:='0';
1:s1:='1';
2:s1:='2';
3:s1:='3';
4:s1:='4';
5:s1:='5';
6:s1:='6';
7:s1:='7';
8:s1:='8';
9:s1:='9';
10:s1:='10';
11:s1:='100';
12:s1:='1000';
13:s1:='10000';
14:s1:='100000';
15:s1:='1000000';
16:s1:='10000000';
end;
result:=s1;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
edit4.Text:=shuzi(edit3.Text);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -