reportbuilder中如何实现大写金额?(100分)

P

pldu

Unregistered / Unconfirmed
GUEST, unregistred user!
在reportbuilder中如何自定义函数或其他方法实现大写金额
 
两个函数,上面的仅仅能够转换正数,下面的可以转换负数,都是摘抄
function XxToDx(const hjnum: real): string;
var
Vstr, zzz, cc, cc1, Presult: string;
xxbb: array[1..12] of string;
uppna: array[0..9] of string;
iCount, iZero, vPoint, vdtlno: integer;
begin
//*设置大写中文数字和相应单位数组*//
xxbb[1] := '亿';
xxbb[2] := '仟';
xxbb[3] := '佰';
xxbb[4] := '拾';
xxbb[5] := '万';
xxbb[6] := '仟';
xxbb[7] := '佰';
xxbb[8] := '拾';
xxbb[9] := '元';
xxbb[10] := '.';
xxbb[11] := '角';
xxbb[12] := '分';
uppna[0] := '零';
uppna[1] := '壹';
uppna[2] := '贰';
uppna[3] := '叁';
uppna[4] := '肆';
uppna[5] := '伍';
uppna[6] := '陆';
uppna[7] := '柒';
uppna[8] := '捌';
uppna[9] := '玖';
Str(hjnum: 12: 2, Vstr);
cc := '';
cc1 := '';
zzz := '';
result := '';
presult := '';
iZero := 0;
vPoint := 0;
for iCount := 1 to 10do
begin
cc := Vstr[iCount];
if cc <> ' ' then
begin
zzz := xxbb[iCount];
if cc = '0' then
begin
if iZero < 1 then
//*对“零”进行判断*//
cc := '零'
else
cc := '';
if iCount = 5 then
//*对万位“零”的处理*//
if copy(result, length(result) - 1, 2) = '零' then
result := copy(result, 1, length(result) - 2) + xxbb[iCount]
+ '零'
else
result := result + xxbb[iCount];
cc1 := cc;
zzz := '';
iZero := iZero + 1;
end
else
begin
if cc = '.' then
begin
cc := '';
if (cc1 = '') or (cc1 = '零') then
begin
Presult := copy(result, 1, Length(result) - 2);
result := Presult;
iZero := 15;
end;
if iZero >= 1 then
zzz := xxbb[9]
else
zzz := '';
vPoint := 1;
end
else
begin
iZero := 0;
cc := uppna[StrToInt(cc)];
end
end;
result := result + (cc + zzz)
end;
end;
if Vstr[11] = '0' then
//*对小数点后两位进行处理*//
begin
if Vstr[12] <> '0' then
begin
cc := '零';
result := result + cc;
cc := uppna[StrToInt(Vstr[12])];
result := result + (uppna[0] + cc + xxbb[12]);
end
end
else
begin
if iZero = 15 then
begin
cc := '零';
result := result + cc;
end;
cc := uppna[StrToInt(Vstr[11])];
result := result + (cc + xxbb[11]);
if Vstr[12] <> '0' then
begin
cc := uppna[StrToInt(Vstr[12])];
result := result + (cc + xxbb[12]);
end;
end;
result := result + '正';
end;

{-------------------------------------------------------------------------------}
function num_str(ls: Variant): string;
var
dx_sz, dx_dw, str_int, str_dec, dx_str, fu: string;
a, b, b2, c, d: string;
num_int, num_dec, len_int, i, a_int, pp: integer;
//dx_str为返回字符串
begin
dx_sz := '零壹贰叁肆伍陆柒捌玖';
dx_dw := '万仟佰拾亿仟佰拾万仟佰拾元';
//处理金额小于零情况
if ls < 0 then
begin
ls := ls * -1;
fu := '负';
end
else
fu := '';
//取得整数值及整数串
dx_str := ls;
if (ls > 0) and (ls < 1) then
dx_str := '0' + dx_str;
pp := pos('.', dx_str);
if pp > 0 then
str_int := copy(dx_str, 1, pos('.', dx_str) - 1)
else
str_int := dx_str;
num_int := strtoint(str_int);
//取得小数值及小数串
if (ls > 0) and (ls < 1) then
num_dec := ls * 100
else
num_dec := (ls - num_int) * 100;
str_dec := inttostr(num_dec);
len_int := Length(str_int);
dx_str := '';
//转换整数部分
for i := 1 to len_intdo
begin
//a为小写数字字符,b为对应的大写字符
//c为对应大写单位,d为当前大写字符串的最后一个汉字
a := copy(str_int, i, 1);
a_int := strtoint(a);
b := copy(dx_sz, (a_int * 2 + 1), 2);
c := copy(dx_dw, ((13 - len_int + i - 1) * 2 + 1), 2);
if dx_str<> '' then
d := copy(dx_str, Length(dx_str) - 1, 2)
else
d := '';
if (b = '零') and ((d = '零') or (b = b2) or (c = '元') or (c = '万') or (c = '亿')) then
b := '';
if (a = '0') and (c <> '元') and (c <> '万') and (c <> '亿') then
c := '';
if ((c = '元') or (c = '万') or (c = '亿')) and (d = '零') and (a = '0') then
begin
dx_str := copy(dx_str, 1, Length(dx_str) - 2);
d := copy(dx_str, Length(dx_str) - 1, 2);
if ((c = '元') and (d = '万')) or ((c = '万') and (d = '亿')) then
c := '';
end;
dx_str := dx_str + b + c;
b2 := b;
end;

//处理金额小于1的情况
if Length(dx_str) <= 2 then
dx_str := '';
//转换小数部分
if (num_dec < 10) and (ls > 0) then
begin
a_int := strtoint(str_dec);
b := copy(dx_sz, (a_int * 2 + 1), 2);
if num_dec = 0 then
dx_str := dx_str + '整';
if num_dec > 0 then
dx_str := dx_str + '零' + b + '分';
end;

if num_dec >= 10 then
begin
a_int := strtoint(copy(str_dec, 1, 1));
a := copy(dx_sz, (a_int * 2 + 1), 2);
a_int := strtoint(copy(str_dec, 2, 1));
b := copy(dx_sz, (a_int * 2 + 1), 2);
if a <> '零' then
a := a + '角';
if b <> '零' then
b := b + '分'
else
b := '';
dx_str := dx_str + a + b;
end;

if ls = 0 then
dx_str := '零元整';
dx_str := fu + dx_str;
//函数返回字符串
Result := dx_str;
end;
 
to:yzhshi
我想在reportbuilder内部实现大写金额,而不是在delphi内实现再通过变量传到报表中的
 
这个基本是不可能的,因为ReportBuilder是E文软件,怎么会考虑中国习惯???[?][:D]
 
不是不可能,reportbuilder可以自定义函数,但我不知道如何写,而且不知道它
的内部有些什么函数
 
reportbuilder内部实现是不可能的,除非你修改源代码。
reportmachine倒是可以。
 
我知道reportmachine可以,但reportmachine调整套打格式很麻烦
 
已解决,在reportbuilder内就可以实现,自定义函数,然后在reportbuilder的ongettext
事件中调用自定义函数就行了。
 
结束贴子了
 
多人接受答案了。
 
顶部