函数名为
Function GetCapsNum(Value: Double:):string;
begin
end;

解决方案 »

  1.   

    //转换一个金额为大写汉字表达。如:1234.56-->壹仟贰佰叁拾肆元伍角陆分.
    function ConvertNumToChinese(CurNum: string): string;
    var
      Str1, IntStr, DigStr: string;
      DigPtr: PChar;
      i, Big1: Integer;
      LastIsZero: Boolean;
    begin
      CurNum := FloatToStr(System.Round(StrToFloat(CurNum) * 100) / 100);
      Result := '';
      Str1 := CurNum;
      DigPtr := StrScan(PChar(Str1), '.');
      if DigPtr = nil then
      begin
        IntStr := Str1;
        DigStr := '';
      end else
      begin
        IntStr := Copy(Str1, 1, DigPtr - PChar(Str1));
        DigStr := Copy(Str1, DigPtr - PChar(Str1) + 2, Length(Str1) - Length(IntStr) - 1);
      end;
      Big1 := length(IntStr);
      LastIsZero := False;
      for i := 1 to Big1 do
      begin
        if (IntStr[i] = '0') and LastIsZero then
          LastIsZero := True
        else
          if (i < Big1) and (IntStr[i] = '0') and (IntStr[i + 1] <> '0')
            and (((Big1 - i) mod 4) <> 0) then
          begin
            Result := Result + getCNum(IntStr[i]);
            LastIsZero := True;
          end
          else
            if (IntStr[i] <> '0') then
            begin
              Result := Result + getCNum(IntStr[i]);
              LastIsZero := False;
            end;    if (IntStr[i] <> '0') or ((IntStr[i] = '0') and (((Big1-i) mod 4) = 0)) then
          Result := Result + getCExp(Big1 - i + 1);
      end;  Result := Result + '元';  Big1 := length(DigStr);
      if Big1 = 0 then
      begin
        Result := Result + '整';
      end
      else
        if (Big1 = 1)and (DigStr <> '0') then
        begin
          Result := Result + getCNum(DigStr[1]);
          Result := Result + '角';
        end
        else
          if Big1 = 2 then
            for i := 1 to Big1 do
              begin
                Result := Result + getCNum(DigStr[i]);
                Result := Result + getCExp(-i);
              end;
    end;
      

  2.   

    function   GetCapsNum(ls:   Variant):   string;  
      var  
          dx_sz,   dx_dw,   str_int,   str_dec,   dx_Str,   fu:   string;   //dx-str为返回字符串  
          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)and(num_dec<10)   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;
      

  3.   

    function TForm811001.GetGapsValue(Value: Double; Flag: Integer = 0): string;
    const
      chNum: array[0..9] of string =
      ('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
      chBit: array[1..9] of string =
      ('圆', '拾', '佰', '仟', '万', '拾万', '佰万', '仟万', '亿');
    var
      __i, __n: Integer;
      __Value, __zero: string;
    begin
      __Value := Format('%.2f', [Value]); //FloatToStr(Value);
      __i := Pos('.', __Value) - 1;
      if __i = 0 then
      begin
        __i := Length(__Value);
      end;  if __i > 12 then //只能支持到千亿
      begin
        Exit;
      end;  Result := '';  if __i >= 5 then
      begin
        Result :=
          GetGapsValue(StrToFloat(Trim(Copy(__Value, 1, __i - 4))), Flag + 1);
        __Value := Trim(Copy(__Value, __i - 3, Length(__Value)));
      end;  if Flag = 0 then
      begin
        Result := StringRePlace(Result, '圆整', '万', [rfIgnoreCase, rfReplaceAll]);
      end
      else
      begin
        Result := StringRePlace(Result, '圆整', '亿', [rfIgnoreCase, rfReplaceAll]);
      end;  __i := Pos('.', __Value) - 1;
      if __i = 0 then
      begin
        __i := Length(__Value);
      end;  while (__i >= 1) and (Length(__Value) > 0) do
      begin
        //处理小数以前的数据
        if Copy(__Value, 1, 1) = '.' then
        begin
          Break;
        end;
        __n := StrToInt(Copy(__Value, 1, 1));
        if __n <> 0 then
        begin
          Result := Result + __zero + chNum[__n] + chBit[__i];
          __zero := '';
        end
        else
        begin
          __zero := '零';
        end;
        __Value := Copy(__Value, 2, Length(__Value));
        __i := __i - 1;
      end;  if Copy(__Value, 1, 1) = '.' then
      begin
        __Value := Copy(__Value, 2, Length(__Value));
      end;  if (Copy(Result, Length(Result) - 1, 2) <> '圆') then
      begin
        Result := Result + '圆';
      end;  if Length(__Value) > 0 then
      begin
        __n := StrToInt(Copy(__Value, 1, 1));
        if __n <> 0 then
        begin
          Result := Result + __zero + chNum[__n] + '角';
          __zero := '';
        end
        else
        begin
          __zero := '零';
        end;
        __Value := Copy(__Value, 2, Length(__Value));
      end;  if Length(__Value) > 0 then
      begin
        __n := StrToInt(Copy(__Value, 1, 1));
        if __n <> 0 then
        begin
          Result := Result + __zero + chNum[__n] + '分';
        end;
      end;
      if (Copy(Result, Length(Result) - 1, 2) = '圆') or
        (Copy(Result, Length(Result) - 1, 2) = '角') or
        (Copy(Result, Length(Result) - 1, 2) = '分') then
      begin
        Result := Result + '整';
      end
      else
      begin
        Result := Result + '圆整';
      end;  Result := StringRePlace(Result, '亿万', '亿', [rfIgnoreCase, rfReplaceAll]);  if (Copy(Result, 1, 4) = '壹拾') then
      begin
        Result := Copy(Result, 3, Length(Result));
      end;  if (Copy(Result, 1, 4) = '圆零') then
      begin
        Result := Copy(Result, 5, Length(Result));
      end;
    end;