如题所问。本人想将任一数字金额,转为英文金额写法,由于本人英文不咋样,不懂如何下手,有哪位做过数似函数的请帮一下。

解决方案 »

  1.   

    基本元素: 0~20, 30, 40, 50, 60, 70, 80, 90, 100, 10^3, 10^6, 10^9
    如:
    1002 翻译成 {1, 10^3, 0, 2}, 0 使用 and, 即是: one thousand and two.
    27314 翻译成 {27, 10^3, 3, 100, 14}, 即是: twenty-seven thousand three hundred fourteen.
      

  2.   

    //将在0.01-99,999999.99之间的数字转换成英文表示法
    //调用本Function时,strDigits不可包含千位分隔符,并且小数部分要保留两位,如果有的话。
    function DigitToEn(strDigits: String; intRMB: Boolean): String;
      //将在1-19之间的数字转换成英文表示法
      function DigitToEn1(strDigits: String): String;
      begin
        Case StrToInt(strDigits) of
          1: Result := 'ONE';
          2: Result := 'TWO';
          3: Result := 'THREE';
          4: Result := 'FOUR';
          5: Result := 'FIVE';
          6: Result := 'SIX';
          7: Result := 'SEVEN';
          8: Result := 'EIGHT';
          9: Result := 'NINE';
          10: Result := 'TEN';
          11: Result := 'ELEVEN';
          12: Result := 'TWELVE';
          13: Result := 'THIRTEEN';
          14: Result := 'FOURTEEN';
          15: Result := 'FifTEEN';
          16: Result := 'SIXTEEN';
          17: Result := 'SEVENTEEN';
          18: Result := 'EIGHTEEN';
          19: Result := 'NINETEEN';
        else
          Result := '';
        end;
      end;
      //将在1-99之间的数字转换成英文表示法
      function DigitToEn2(strDigits: String): String;
      var
        strTemp: String;
      begin
        if StrToInt(strDigits) < 20 then
          Result := DigitToEn1(strDigits)
        else begin
          Case StrToInt(Left(strDigits, 1)) of
            2: strTemp := 'TWENTY';
            3: strTemp := 'THIRTY';
            4: strTemp := 'FORTY';
            5: strTemp := 'FIFTY';
            6: strTemp := 'SIXTY';
            7: strTemp := 'SEVENTY';
            8: strTemp := 'EIGHTY';
            9: strTemp := 'NINETY';
          else
            strTemp := '';
          end;
          
          if Right(strDigits, 1) <> '0' then
              strTemp := strTemp + '-' + DigitToEn1(Right(strDigits, 1));      Result := strTemp;
        end;
      end;
      //将在1-999之间的数字转换成英文表示法
      //如intFormat为1,则在HUNDRED 后面就有 AND,否则没有。
      function DigitToEn3(strDigits: String; intFormat: Integer): String;
      begin
        //去掉数字串前面的0
        strDigits := IntToStr(StrToInt(strDigits));    if StrToFloat(strDigits) <= 19 then
          Result := DigitToEn1(strDigits)
        else if (StrToFloat(strDigits) >= 20) and (StrToFloat(strDigits) <= 99) then
          Result := DigitToEn2(strDigits)
        else begin
          Result := DigitToEn1(Left(strDigits, 1)) + ' HUNDRED';
          if (StrToFloat(Right(strDigits, 2)) > 0) and
            (StrToFloat(Right(strDigits, 2)) < 20) then
            if intFormat = 1 then
              Result := Result + ' AND ' + DigitToEn1(Right(strDigits, 2))
            else
              Result := Result + ' ' + DigitToEn1(Right(strDigits, 2))
          else if (StrToFloat(Right(strDigits, 2)) >= 20)
            and (StrToFloat(Right(strDigits, 2)) <= 99) then
            if intFormat = 1 then
              Result := Result + ' AND ' + DigitToEn2(Right(strDigits, 2))
            else
              Result := Result + ' ' + DigitToEn2(Right(strDigits, 2));
        end;
      end;var
      // 整数部份 小数部份
      strInteger, strDecimal: String;
      strTemp: String;
    begin
      if (StrToFloat(strDigits) > 99999999.99) or
        (StrToFloat(strDigits) < 0.01) then
        raise exception.Create('Out of range, must between 0.01 - 99999999.99');  //有整数部分及小数部分
      if (Int(StrToFloat(strDigits)) > 0) and
        (StrToFloat(strDigits) - Int(StrToFloat(strDigits)) > 0) then
      begin
        strInteger := Left(strDigits, Pos('.', strDigits) - 1);
        strDecimal := Right(strDigits, Length(strDigits) - Pos('.', strDigits));
      end
      //只有整数部分
      else if Int(StrToFloat(strDigits)) > 0 then
        strInteger := IntToStr(Round(StrToFloat(strDigits)))
      //只有小数部分
      else if StrToFloat(strDigits) - Int(StrToFloat(strDigits)) > 0 then
        strDecimal := Right(strDigits, Length(strDigits) - Pos('.', strDigits));  //得到整数部分英文表示法
      if strInteger <> '' then begin
        strTemp := DigitToEn3(Right(strInteger, 3), 1);
        if Length(strInteger) > 3 then begin
          strTemp := DigitToEn3(Left(Right(strInteger, 6),
            Length(Right(strInteger, 6)) - 3), 2) + ' THOUSAND ' + strTemp;
          if Length(strInteger) > 6 then
            strTemp := DigitToEn3(Left(strInteger, Length(strInteger) - 6), 2) +
            ' MILLION ' + strTemp;
        end;
        strInteger := strTemp;
      end;  if (strDecimal <> '') and (Length(strDecimal) <= 3) then
        strDecimal := DigitToEn3(strDecimal, 1);  if (strInteger <> '') and (strDecimal <> '') then
        if intRMB then
          Result := strInteger + ' YUANS AND ' + strDecimal + ' CENTS ONLY'
        else
          Result := strInteger + ' DOLLARS AND ' + strDecimal + ' CENTS ONLY'
      else if strInteger <> '' then
        if intRMB then
          Result := strInteger + ' YUANS ONLY'
        else
          Result := strInteger + ' DOLLARS ONLY'
      else if strDecimal <> '' then
        Result := strDecimal + ' CENTS ONLY'
      else
        Result := 'ZERO';
    end;
      

  3.   

    多谢Naner_china(Naner)的帮助,多谢Kyee(浪子阿鹏)。
    Naner_china(Naner)的函数给得非常细致周到,再次致谢。
    ------------------------------------
    lc406