如题所问。本人想将任一数字金额,转为英文金额写法,由于本人英文不咋样,不懂如何下手,有哪位做过数似函数的请帮一下。
解决方案 »
- 关于combobox加载两个字段数据的问题,还望大家赐教!!!!
- Delphi与C++Builder混合编程问题(Delphi窗体怎样嵌入到C++builer中)
- 地图编辑器画菱形格子后,如何正确选中菱形范围。
- 用鼠标右键单击文件或者文件夹时弹出的那个菜单显示路径??
- 怎样往打开文件对话框和Explorer(注意不是IE)中添加自己需要的按钮
- 按下首字母,自动找到相应的item(LISTBOX),怎样做?
- xt_delphi小兄弟,没有在这里玩过,有一个帖子结贴时把分都加给我.弄的我都.....散分散分,希望大家原谅
- windows xp 的序列号?
- 做网管要掌握什么知识和技能?
- 斑竹,,请问我的的两个分数是111帖子怎么没有了?我还没结帐那?是找小新的,,
- 我下载了delphi2005 光盘版的 不知道怎么安装
- 请问如何创建多窗体的应用程序?大家不用笑哦--菜鸟
如:
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.
//调用本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;
Naner_china(Naner)的函数给得非常细致周到,再次致谢。
------------------------------------
lc406