N
ntjrr
Unregistered / Unconfirmed
GUEST, unregistred user!
我先选择新建一个单元(而不是新建FORM),然后代码如下:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
implementation
function Changdx2(mmje: Double): String;
const s1: String = '零壹贰叁肆伍陆柒捌玖';
s2: String = '分角元拾佰仟万拾佰仟亿拾佰仟万';
function StrTran(const S, S1, S2: String): String;
begin
Result := StringReplace(S, S1, S2, [rfReplaceAll]);
end;
var s, dx: String;
i, Len: Integer;
begin
if mmje < 0 then
begin dx := '负';
mmje := -mmje;
end;
s := Format('%.0f', [mmje*100]);
Len := Length(s);
for i := 1 to Len do
dx := dx + Copy(s1, (Ord(s) - Ord('0'))*2 + 1, 2) + Copy(s2, (Len - i)*2 + 1, 2);
dx := StrTran(StrTran(StrTran(StrTran(StrTran(dx, '零仟', '零'), '零佰', '零'), '零拾', '零'), '零角', '零'), '零分', '整');
dx := StrTran(StrTran(StrTran(StrTran(StrTran(dx, '零零', '零'), '零零', '零'), '零亿', '亿'), '零万', '万'), '零元', '元');
if dx = '整' then Result := '零元整'
else Result := StrTran(StrTran(dx, '亿万', '亿零'), '零整', '整');
end;
然后要用到这个单元的地方uses unit4 然后就直接使用Changdx2了,这样对不对?
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
implementation
function Changdx2(mmje: Double): String;
const s1: String = '零壹贰叁肆伍陆柒捌玖';
s2: String = '分角元拾佰仟万拾佰仟亿拾佰仟万';
function StrTran(const S, S1, S2: String): String;
begin
Result := StringReplace(S, S1, S2, [rfReplaceAll]);
end;
var s, dx: String;
i, Len: Integer;
begin
if mmje < 0 then
begin dx := '负';
mmje := -mmje;
end;
s := Format('%.0f', [mmje*100]);
Len := Length(s);
for i := 1 to Len do
dx := dx + Copy(s1, (Ord(s) - Ord('0'))*2 + 1, 2) + Copy(s2, (Len - i)*2 + 1, 2);
dx := StrTran(StrTran(StrTran(StrTran(StrTran(dx, '零仟', '零'), '零佰', '零'), '零拾', '零'), '零角', '零'), '零分', '整');
dx := StrTran(StrTran(StrTran(StrTran(StrTran(dx, '零零', '零'), '零零', '零'), '零亿', '亿'), '零万', '万'), '零元', '元');
if dx = '整' then Result := '零元整'
else Result := StrTran(StrTran(dx, '亿万', '亿零'), '零整', '整');
end;
然后要用到这个单元的地方uses unit4 然后就直接使用Changdx2了,这样对不对?