转成中文大写 // 数字转大写金额 class function TFTFloatFunc.RMBFloatToChinese(ARMBCash: Real): string; const cNum: WideString = '零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分'; cCha: array [0 .. 1, 0 .. 11] of string = (('零仟', '零佰', '零拾', '零零零', '零零', '零亿', '零万', '零元', '亿万', '零角', '零分', '零整'), ('零', '零', '零', '零', '零', '亿', '万', '元', '亿', '零', '整', '整')); var i: Integer; sNum: WideString; begin Result := ''; sNum := FormatFloat('0', ARMBCash * 100); for i := 1 to Length(sNum) do Result := Result + cNum[Ord(sNum[i]) - 47] + cNum[26 - Length(sNum) + i]; for i := 0 to 11 do // 去掉多余的零 Result := StringReplace(Result, cCha[0, i], cCha[1, i], [rfReplaceAll]);
end;
转成 英文大写 class function TFTFloatFunc.RMBFloatToEnglish(ARMBCash: Real ; intRMB: Boolean): string; function Left(const AStr: string; ACount: Integer): string; begin Result := Copy(astr,1,ACount); end;
function Right(const AStr: string; ACount: Integer): string; begin Result := Copy(astr,Length(AStr)-acount+1, ACount); end;
//将在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 AND'; if (StrToFloat(Right(strDigits, 2)) > 0) and (StrToFloat(Right(strDigits, 2)) < 20) then if intFormat = 1 then Result := Result + ' '+DigitToEn1(Right(strDigits, 2)) //' AND ' + 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 + ' ' + DigitToEn2(Right(strDigits, 2)) //AND else Result := Result + ' ' + DigitToEn2(Right(strDigits, 2)); end; end;
var // 整数部份 小数部份 strInteger, strDecimal: String; strTemp: String; strDigits :string; begin //只能到千亿,万亿其实是没有意义的 if (ARMBCash > 999999999999.99) or ( ARMBCash< 0.01) then raise exception.Create('Out of range, must between 0.01 - 999999999999.99'); strDigits:= FloatToStr(ARMBCash); //有整数部分及小数部分 if (Int(ARMBCash) > 0) and (ARMBCash - Int(ARMBCash) > 0) then begin strInteger := Left(strDigits, Pos('.', strDigits) - 1); strDecimal := Right(strDigits, Length(strDigits) - Pos('.', strDigits)); end //只有整数部分 else if Int(ARMBCash) > 0 then strInteger := IntToStr(System.Round(ARMBCash)) //只有小数部分 else if ARMBCash - Int(ARMBCash) > 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 AND ' + strTemp; //百万以上 if Length(strInteger) > 6 then strTemp := DigitToEn3(Left(strInteger, Length(strInteger) - 6), 2) + ' MILLION AND ' + strTemp; //十亿以上 if Length(strInteger) > 9 then strTemp := DigitToEn3(Left(strInteger, Length(strInteger) - 9), 2) + ' BILLION AND ' + 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; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论