做一个转换函数,把数字变成“千百元。。。”的金额字符串。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
function SmallTOBig(small_str: string): string;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text := smalltobig('12345.67');
end;
function TForm1.SmallTOBig(small_str: string): string;
var
SmallMonth,BigMonth:string;
wei1,qianwei1:string[2];
wei,qianwei,dianweizhi,qian:integer;
small:real;
begin
small:=StrToFloat(small_str);
{------- 修改参数令值更精确 -------}
qianwei:=-2;//小数点后的位置,需要的话也可以改动-2值
Smallmonth:=formatfloat('0.00',small);//转换成货币形式,需要的话小数点后加多几个零
dianweizhi :=pos('.',Smallmonth);//小数点的位置
for qian:=length(Smallmonth)do
wnto 1do
//循环小写货币的每一位,从小写的右边位置到左边
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
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;
//case
inc(qianwei);
BigMonth :=wei1+qianwei1+BigMonth;{组合成大写金额}
end;
//if
end;
//for
SmallTOBig:=BigMonth;
end;
end.