以前那了人家的东西!今天拿来测试。 发现了一个问题? 少一分钱........不
懂是那里出问题.如:输入(125.80)得到的结果是:壹佰贰拾伍元柒角玖分
   function  Tpinyincodefrm.XTOD(I:real):string;
  const
    d='零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿';
   var
     m,K:string;
     j:integer;
    begin
      k:='';
      m:=floattostr(int(I*100));
      
    for J:=length(M) downto  1  do
      begin
       K:=k+d[(strtoint(m[length(M)-j+1]))*2+1]+d[(strtoint(m[length(M)-j+1]))*2+2]+d[(10+j)*2-1]+d[(10+j)*2];
      end;
请各位试试!

解决方案 »

  1.   

    这个不行,这里有:
    http://expert.csdn.net/Expert/topic/1850/1850748.xml?temp=.7001764
      

  2.   

    function show(v_1:integer):string;
    begin
      case v_1 of
      1: result:='分';
      2: result:='角';
      3: result:='';
      4: result:='';
      5: result:='拾';
      6: result:='佰';
      7: result:='仟';
      8: result:='';
      9: result:='拾';
      10: result:='佰';
      11: result:='仟';
      12: result:='億';
      13: result:='拾';
      end;
    end;function smalltobig1(v_no:integer):string;
    begin
      case v_no of
      0: result:='零';
      1: result:='壹';
      2: result:='貳';
      3: result:='參';
      4: result:='肆';
      5: result:='伍';
      6: result:='陸';
      7: result:='柒';
      8: result:='捌';
      9: result:='玖';
      end;
    end;function big(v_str:string):string;
    var v_len,i,j,k,a:integer;
        v_str1,v_str2:string;
        v_flag,v_flag1:integer;
    begin
      a:=1;
      v_flag:=0;  //元的標志
      v_flag1:=0; //萬的標志
      v_str2:='';
      v_len:=length(v_str);
      if v_len>13 then exit;
      v_str1:=copy(v_str,v_len-2,1);
      if v_str1<>'.' then
        begin
          v_str1:=copy(v_str,v_len-1,1);
          if v_str1<>'.' then
            v_str:=v_str+'.00'
          else
            v_str:=v_str+'0';
        end;
      v_len:=length(v_str);
      if v_len>13 then exit;
      k:=1;
      for i:=1 to v_len do
      begin
        v_str1:=copy(v_str,v_len-i+1,1);
        if v_str1<>'.' then
        begin
          j:=strtoint(v_str1);
          if (j<>0) and (k>=3) then v_flag:=v_flag+1;
          if (j<>0) and (k>=8) and (k<=11) then v_flag1:=v_flag1+1;
          if j<>0 then     //數字不為0
            v_str1:=smalltobig1(j)+show(k)
          else if (a<>0) and (i<>1) and (i<>4) then v_str1:=smalltobig1(j)  //上一位為0且不為分位且不為'.'
          else v_str1:='';
          if (a=0) and (i=13) and (j<>0) then  v_str1:=v_str1+'億'; //億位為0﹐但十億位不為0
          if (k>=8) and (k<=11) and (v_flag1=1) and (j<>0) then  v_str1:=v_str1+'萬'; //沒有萬則加上萬
          if (k>=3) and  (v_flag=1) and (j<>0) then  v_str1:=v_str1+'圓'; //沒有圓則加上圓
          v_str2:=v_str1+v_str2;
          a:=j;
        end;
        k:=k+1;
      end;
      result:=v_str2;
    end;
      

  3.   

    呵呵,我也用了,也发现这个问题,不过实在不知原因,建议换个看看,这里
    http://expert.csdn.net/Expert/topic/1850/1850748.xml?temp=.4518244
      

  4.   

    应该是real类型的精度问题,建议你用两个int表示money,一个是小数点以前的,一个是小数点以后的(即角分),避免四舍五入的问题。
      

  5.   

    修改了下你的函数,但还有一个问题没有解决,就是如果达到十亿就不能显示了function  Tpinyincodefrm.XTOD(I:real):string;
      const
        d='零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿';
       var
         m,K:string;
         j,Ix:integer;
        begin
          k:='';
          ix:=pos('.',floattostr(I)) ;
          m:=Copy(floattostr(I),1,ix-1);
          m:=m+Copy(floattostr(I),ix+1,length(floattostr(I))-ix) ;    for J:=length(M) downto  1  do
          begin
           K:=k+d[(strtoint(m[length(M)-j+1]))*2+1]+d[(strtoint(m[length(M)-j+1]))*2+2]+d[(10+j)*2-1]+d[(10+j)*2];
          end;
          Result := k;
    end ;
      

  6.   

    n[10]:='零'; n[1]:='壹'; n[2]:='貳'; n[3]:='參'; n[4]:='肆'; n[5]:='伍';
    n[6]:='陸';  n[7]:='柒'; n[8]:='捌';  n[9]:='玖';  p[1]:='拾'; p[2]:='佰';
    p[3]:='仟';  p[4]:='萬'; p[5]:='億';
    //-----------------------------------------------------
    if small<=9999999999.99 then
    begin
    x:=small;
    sx:=floattostr(int(x));
    for i:=1 to 10-length(sx) do
    sx:='a'+sx;
    {十億位}
    if (sx[1]<>'a')and(sx[1]<>'0') then
      begin
      m:=strtoint(sx[1]);
      str:=str+n[m]+p[1];
      end;
    {億位}
    if (sx[2]<>'a')and(sx[2]<>'0') then
      begin
      m:=strtoint(sx[2]);
      str:=str+n[m]+p[5];
      end;
    if sx[2]='0' then
      str:=str+p[5];
    {仟萬位}
    if (sx[3]<>'a')and(sx[3]<>'0') then
      begin
      m:=strtoint(sx[3]);
      str:=str+n[m]+p[3];
      end;
    if (sx[3]<>'a')and(sx[3]='0')and(sx[4]<>'0') then
      str:=str+'零';
    {佰萬位}
    if (sx[4]<>'a')and(sx[4]<>'0') then
      begin
      m:=strtoint(sx[4]);
      str:=str+n[m]+p[2];
      end;
    if (sx[4]<>'a')and(sx[4]='0')and(sx[5]<>'0') then
      str:=str+'零';
    {拾萬位}
    if (sx[5]<>'a')and(sx[5]<>'0') then
      begin
      m:=strtoint(sx[5]);
      str:=str+n[m]+p[1];
      end;
    if (sx[5]<>'a')and(sx[5]='0')and(sx[6]<>'0') then
      str:=str+'零';
    {萬位}
    if (sx[6]<>'a')and(sx[6]<>'0') then
      begin
      m:=strtoint(sx[6]);
      str:=str+n[m]+p[4];
      end
       else
       if ((sx[3]<>'0')and(sx[3]<>'a'))or((sx[4]<>'0')and(sx[4]<>'a'))or((sx[5]<>'0')and(sx[5]<>'a')) then
       str:=str+p[4];
    if (sx[6]='0')and(sx[3]='0')and(sx[4]='0')and(sx[5]='0')and(sx[7]<>'0')then
        str:=str+'零';
    {仟位}
    if (sx[7]<>'a')and(sx[7]<>'0') then
      begin
      m:=strtoint(sx[7]);
      str:=str+n[m]+p[3];
      end;
    if (sx[7]<>'a')and(sx[7]='0')and(sx[8]<>'0') then
      str:=str+'零';
    {佰位}
    if (sx[8]<>'a')and(sx[8]<>'0') then
      begin
      m:=strtoint(sx[8]);
      str:=str+n[m]+p[2];
      end;
    if (sx[8]<>'a')and(sx[8]='0')and(sx[9]<>'0') then
      str:=str+'零';
    else
    Application.MessageBox('超出範圍,不能轉換!!!',Pchar(Application.Title),MB_OK+MB_ICONWARNING);