⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 通过本程序实现将小写金额转换为大写!用于新手学习!
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    function convert(money:real):string;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function tform1.convert(money:real):string;
var
  small:string;
  bigchar,powerchar:string[2];//汉字占用两个字节
  power,dotpos,i:integer;
begin
  power:=-2; //字符权值,小数点后面为负数
  //将浮点数转换为字符串,小数点后面保留两位
  small:=formatfloat('0.00',money);
  //取得小数点的位置
  dotpos:=pos('.',small);
  //从右向左转换
  for i:=length(small) downto 1 do
  begin
    if i=dotpos then continue;//小数点则不用转换
    //将字符转换为整数 0-9
    case strtoint(copy(small,i,1)) of
    1:bigchar:='壹';
    2:bigchar:='贰';
    3:bigchar:='叁';
    4:bigchar:='肆';
    5:bigchar:='伍';
    6:bigchar:='陆';
    7:bigchar:='柒';
    8:bigchar:='捌';
    9:bigchar:='玖';
    0:bigchar:='零';
    end;
    //根据权值计算金额单位
    case power of
     -3:powerchar:='厘';
     -2:powerchar:='分';
     -1:powerchar:='角';
     0:powerchar:='元';
     1,5,9:powerchar:='拾';
     2,6,10:powerchar:='佰';
     3,7,11:powerchar:='仟';
     4,12:powerchar:='万';
     8:powerchar:='亿';
   end;
   //提高权值一位
   inc(power);
   //依次取得转换结果
   result:=bigchar+powerchar+result;
 end;
end;


procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
try
  label2.Caption:=convert(strtofloat(edit1.Text));
except
  showmessage('输入的数值无效!');
end;

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -