我用fastreport3 作报表时,有一金额合计栏 [SUM(,MasterData1,2)] ,但显示为小写,请教如何才能显示为大写,下面是我用的代码,先定义MoneyCn,但运行后却有问题,请帮忙查看,谢谢!function MoneyCn(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[i]) - 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;
procedure Tyingfu.FormCreate(Sender: TObject);
begin
DateTimePicker1.Date:=StartOfTheMonth(Now);
DateTimePicker2.Date:=Now;
frxReport1.AddFunction('function MoneyCn(mmje: Double): String;','Myfunction','小写金额转大写的函数');
end;function Tyingfu.frxReport1UserFunction(const MethodName: String;
var Params: Variant): Variant;
begin
if UpperCase(MethodName) = UpperCase('MoneyCn') then
Result := MoneyCn(Params[0]);
end;
end.
我将述代码加入后,调用MoneyCn,如果用 MoneyCn([SUM(,MasterData1,2)]) 时,显示结果为 MoneyCn(78160),而不是大写,我测试直接用 [MoneyCn(78160)],就可以出来,不知是何原因
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[i]) - 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;
procedure Tyingfu.FormCreate(Sender: TObject);
begin
DateTimePicker1.Date:=StartOfTheMonth(Now);
DateTimePicker2.Date:=Now;
frxReport1.AddFunction('function MoneyCn(mmje: Double): String;','Myfunction','小写金额转大写的函数');
end;function Tyingfu.frxReport1UserFunction(const MethodName: String;
var Params: Variant): Variant;
begin
if UpperCase(MethodName) = UpperCase('MoneyCn') then
Result := MoneyCn(Params[0]);
end;
end.
我将述代码加入后,调用MoneyCn,如果用 MoneyCn([SUM(,MasterData1,2)]) 时,显示结果为 MoneyCn(78160),而不是大写,我测试直接用 [MoneyCn(78160)],就可以出来,不知是何原因
解决方案 »
- idHttp提取校检码
- delphi 中如何从数据库中读取数据自生成TreeView,只有两个字段,数据库结构如下。急急!!
- ImageList的图片色彩模式和显示清晰度的问题
- 请问?窗体最小化会激活哪个事件?在运行时我怎么才能获取窗体当前的状态?
- svchost.exe文件是什么东东,怎么我的电脑提示错误!!
- 工作好烦, 心情不好, 软件改了又改, 对MM都没兴趣了. 散分, 希望散掉郁闷.
- 本人初学DELPHI:关于WINDOWS消息的一个巨愚的问题,入即给分
- 自学考试报了《电子技术》、《通信技术专业》的前辈请进?
- 使用olecontainer时,如何在运行时指定 OLE对象?
- dbgrid和一个临时表相连,怎样才能在dbgrid修改后更新到临时表?
- XML 编码转换(gb2312 to utf-8)怎么实现?
- 25岁生日..散分庆祝
Function IIF( b :boolean; s1,s2 :string) :string;
begin if b then IIF:= s1 else IIF:=s2;
end; //本函数的功能一目了然: 当b为真时返回s1,否则返回s2
Const c= '零壹贰叁肆伍陆柒捌玖◇分角圆拾佰仟万拾佰仟亿拾佰仟万';
var L,i,n, code :integer; Z :boolean; s,s1,s2 :string;
begin
s:= FormatFloat('0.00', n0);
L:= Length( s);
Z:= n0<1;
For i:= 1 To L-3 do
begin
Val( Copy( s, L-i-2, 1), n, code);
s1:=IIf( (n=0) And (Z Or (i=9) Or (i=5) Or (i=1)), '', Copy( c, n*2+1, 2))
+ IIf( (n=0) And ((i<>9) And (i<>5) And (i<>1) Or Z And (i=1)), '', Copy( c, (i+13)*2-1, 2))
+ s1;
Z:= (n=0);
end;
Z:= False;
For i:= 1 To 2 do
begin
Val( Copy( s, L-i+1, 1), n, code);
s2:= IIf( (n=0) And ((i=1) Or (i=2) And (Z Or (n0<1))), '', Copy( c, n*2+1, 2))
+ IIf( (n>0), Copy( c,(i+11)*2-1, 2), IIf( (i=2) Or Z, '', '整'))
+ s2;
Z:= (n=0);
end;
For i:= 1 To Length( s1) do If Copy(s1, i, 4) = '亿万' Then Delete(s1,i+2,2);
numToMoney:= IIf(n0=0, '零', s1+s2);
End;