老问题,大小货币转换(200分)

  • 主题发起人 主题发起人 huajianguo
  • 开始时间 开始时间
H

huajianguo

Unregistered / Unconfirmed
GUEST, unregistred user!
不要100200=‘壹拾零万零仟贰佰零合零元正’那种,要‘壹拾万零贰佰元正’。
多谢原代码!200大洋!
 
我有用于实际商业系统的java版和javascript版,没有delphi版的,
事实上我的版本也是在大富翁上搜索到的pascal版本自己改写的,
你仔细搜索以前的帖子。
 
unit ZhuanHuan;

interface

uses
Windows, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, Buttons,shellapi, ExtCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Edit2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Function DXZhuanHuan(f : String) : String;
implementation

{$R *.DFM}

Function DXZhuanHuan(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
begin
if (copy(f,1,1)='0') and (copy(f,2,1)='.') then
fs:='零' else
fs:='';
end;

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
jg := jg + copy(dx, strtoint(copy(xs,i,1))*2 + 1, 2);

End;
DXZhuanHuan := fs+jg;
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
try
edit2.text:=DXzhuanhuan(Edit1.Text);
except
messagebox(handle,pchar('你输入的'+'"'+edit1.text+'"'+'是非法数值!'),'警告',mb_ok+mb_iconwarning);
edit1.Text:='';
end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then Button1.Click;
// if (key<'0') or (key>'9')or (key<>'.' )then
// if key<>chr(8) then key:=chr(0);
end;

procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label1.Font.Color:=clBlue;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label1.Font.Color:=clBlack;
label2.Font.Color:=clBlack;
button1.Font.Color:=clBlack;
end;

procedure TForm1.Edit2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label2.Font.Color:=clBlue;
end;

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Button1.Font.Color:=clBlue;
end;

end.
 
其實自己寫也是可以寫出來的
只不過要多一些判斷罷了
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部