在fastreport里怎样能使金额从小写转变成大写?

13023600339 2001-07-11 01:18:29
或者可以提供具体的算法用pascal怎样实现?
赚分的机会啊!!!!
...全文
447 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingsong 2001-08-08
  • 打赏
  • 举报
回复
你怎么不到delphi版去问,这个问题提过的,以下为转贴的
该函数能有效解决中间多个0只显示一个0的问题,至于英文应该类似
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;
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_int do
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;
13023600339 2001-08-08
  • 打赏
  • 举报
回复
关注!
13023600339 2001-08-07
  • 打赏
  • 举报
回复
这里有没有高手啊?
frman 2001-08-07
  • 打赏
  • 举报
回复
5555555~~~~~这个不懂,啥是fastreport啊~~~:)

嘿嘿。。。同意楼上的:)))嘿嘿。。。
one_add_one 2001-08-07
  • 打赏
  • 举报
回复
见者有份!
13023600339 2001-08-07
  • 打赏
  • 举报
回复
我要给分了!
13023600339 2001-08-07
  • 打赏
  • 举报
回复
想要转换成英文呢?英文的读法我就有点弄不清,各位仁兄还有什么高见,请速速道来!
dana 2001-07-17
  • 打赏
  • 举报
回复
字符串处理
将12345678.99转换成12,345,678.99
方法:
var
n : DOUBLE ;
begin
n:=12345678.99;
ShowMessage(Format('%*.*n',[10,2,n]));
end;


小写金额转换
  如下为一个简单的小写金额转换为大写的函数,其思路简单(可以说烂吧,居然利用了位置来转换),但是它几乎可以无限制的转换,只要你能读得出来和写得进去:
function Tform1.SmallTOBig(small:real):string;
var SmallMonth,BigMonth:string;
wei1,qianwei1:string[2];
wei,qianwei,dianweizhi,qian:integer;
begin
{------- 修改参数令值更精确 -------}
qianwei:=-2;{小数点后的位置,需要的话也可以改动-2值}
Smallmonth:=formatfloat('0.00',small);{转换成货币形式,需要的话小数点后加多几个零}
{---------------------------------}
dianweizhi :=pos('.',Smallmonth);{小数点的位置}
for qian:=length(Smallmonth) downto 1 do{循环小写货币的每一位,从小写的右边位置到左边}
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 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;
inc(qianwei);
BigMonth :=wei1+qianwei1+BigMonth;{组合成大写金额}
end;
end;
SmallTOBig:=BigMonth;
end;
调用如下“edit1.text:=SmallTOBig(1234567890.1234);”他自动默认小数点后两位


替换指定串函数
一个替换指定串的函数,从一个字符串中找出指定子串,并替换为另一子串。
function replacing(S,source,target:string):string;
var site,StrLen:integer;
begin
{source在S中出现的位置}
site:=pos(source,s);
{source的长度}
StrLen:=length(source);
{删除source字符串}
delete(s,site,StrLen);
{插入target字符串到S中}
insert(target,s,site);
{返回新串}
replacing:=s;
end;


wg613 2001-07-17
  • 打赏
  • 举报
回复
送你一个函数
function SmallTOBig(small:real):string;
var
SmallMonth,BigMonth:string;
wei1,qianwei1:string[2];
wei,qianwei,dianweizhi,qian:integer;
begin
qianwei:=-2; //小数点后的位置,需要的话也可以改动-2值,(修改参数令值更精确)
Smallmonth:=formatfloat('0.00',small);//转换成货币形式,需要的话小数点后加多几个零
dianweizhi :=pos('.',Smallmonth);//小数点的位置
for qian:=length(Smallmonth) downto 1 do//循环小写货币的每一位,从小写的右边位置到左边
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 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;
inc(qianwei);
BigMonth :=wei1+qianwei1+BigMonth;//组合成大写金额
end;
end;
SmallTOBig:=BigMonth;
end;

33,027

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧