收藏:function changeMoney(TM:real):string ; //金额转换from http://search.csdn.net/Expert/topic/2605/2605104.xml?temp=.1051447

function changeMoney(TM:real):string ;     //金额转换
var
 shu:array of string[2];
 shu1:array of string[2];
  shuzi,zifu:string;temp1:integer;
begin
 setlength(shu,10);setlength(shu1,10);
  shu[9]:='仟';shu[8]:='佰';shu[7]:='拾';shu[6]:='万';
  shu[5]:='仟';shu[4]:='伯';shu[3]:='拾';shu[2]:='圆';
  shu[1]:='角';shu[0]:='分';
  shu1[0]:='零';shu1[1]:='壹';shu1[2]:='贰';
  shu1[3]:='叁';shu1[4]:='肆';shu1[5]:='伍';
  shu1[6]:='陆';shu1[7]:='柒';shu1[8]:='捌';
  shu1[9]:='玖';
  shuzi:=inttostr(round(tm*100));
  if tm>99999999.99 then
   result:='数据溢出,错误'
  else
    begin
     zifu:='';
      temp1:=1;
      while temp1<=length(shuzi) do
       begin
         if copy(shuzi,temp1,1)<>'0' then
           begin
             if copy(shuzi,temp1-1,1)='0' then zifu:=zifu+shu1[0];
              zifu:=zifu+shu1[strtoint(copy(shuzi,temp1,1))]+shu[length(shuzi)-temp1];
            end;
          if copy(shuzi,temp1,1)='0' then
           begin
             if temp1=length(shuzi)-2 then zifu:=zifu+shu[2];
              if temp1=length(shuzi)-6 then zifu:=zifu+shu[6];
            end;
          temp1:=temp1+1
        end;
      result:=zifu;
    end;
end;

//fastreport版
begin
  shu[9]:='仟';shu[8]:='佰';shu[7]:='拾';shu[6]:='万';
  shu[5]:='仟';shu[4]:='伯';shu[3]:='拾';shu[2]:='圆';
  shu[1]:='角';shu[0]:='分';
  shu1[0]:='零';shu1[1]:='壹';shu1[2]:='贰';
  shu1[3]:='叁';shu1[4]:='肆';shu1[5]:='伍';
  shu1[6]:='陆';shu1[7]:='柒';shu1[8]:='捌';
  shu1[9]:='玖';
  shuzi:=[STR(ROUND([SUM([ADOTable1."金额"])]* 100))];
  if [SUM([ADOTable1."金额"]>99999999.99 then
    result:='数据溢出,错误'
  else
    begin
      zifu:='';
      temp1:=1;
      while temp1<=length(shuzi) do
      begin
        if copy(shuzi,temp1,1)<>'0' then
          begin
            if copy(shuzi,temp1-1,1)='0' then zifu:=zifu+shu1[0];
              zifu:=zifu+shu1[[INT(copy(shuzi,temp1,1))]]+shu[length(shuzi)-temp1];
            end;
          if copy(shuzi,temp1,1)='0' then
          begin
            if temp1=length(shuzi)-2 then zifu:=zifu+shu[2];
              if temp1=length(shuzi)-6 then zifu:=zifu+shu[6];
            end;
          temp1:=temp1+1
        end;
      result:=zifu;
    end;
  memo.clear;
  memo.add(result);
end
posted on 2004-09-17 15:37  wenew  阅读(464)  评论(1编辑  收藏  举报