如:291.71-->Two Hundred Ninety One and Seventy One Cents
解决方案 »
- 请教大侠delphi如何回调Webbrowser中的JS函数
- 关于Excel导入的简单问题,马上给分!
- 请问:D7中菜单的背景色和字体颜色怎么设置……????
- WM_NCMOUSEMOVE 消息中,如何判断 是否在 标题栏??
- 谁知道有没有delphi帮助的汉化!!
- 测试”ADO应用程序服务器“时为什么不能保存?????!!!!!
- 程序用到ADO,Delphi6附带的InstallShield打包时该选哪个?还有我机器上ADO版本较新,发布时需不需要考虑别人的ADO版本呢?InstallShield
- cell---强大的二次报表开发工具
- 帮忙
- 请教?如何将一个目录进行压缩存为.ZIP格式,可否做到,有源代码者,不胜感激!!!!
- 关于会计系统设计的一点问题,望高手指点~~~~
- 如果edit里的数字有改变,然后把q:array[1..7]的值全置为零
我的E_Mail: [email protected]
50分是你的.
function zr4(y)' 准备数据
dim z(10)
z(1)="ONE"
z(2)="TWO"
z(3)="THREE"
z(4)="FOUR"
z(5)="FIVE"
z(6)="SIX"
z(7)="SEVEN"
z(8)="EIGHT"
z(9)="NINE"
zr4=z(MID(y,1,1))
end functionfunction zr3(y)' 准备数据
dim z(10)
z(1)="ONE"
z(2)="TWO"
z(3)="THREE"
z(4)="FOUR"
z(5)="FIVE"
z(6)="SIX"
z(7)="SEVEN"
z(8)="EIGHT"
z(9)="NINE"
zr3=z(MID(y,3,1))
end function
function zr2(y)' 准备数据dim z(20)
z(10)="TEN"
z(11)="ELEVEN"
z(12)="TWELVE"
z(13)="THIRTEEN"
z(14)="FOURTEEN"
z(15)="FIFTEEN"
z(16)="SIXTEEN"
z(17)="SEVENTEEN"
z(18)="EIGHTEEN"
z(19)="NINETEEN"
zr2=z(MID(y,2,2))end functionfunction zr1(y)' 准备数据dim z(10)
z(1)="TEN"
z(2)="TWENTY"
z(3)="THIRTY"
z(4)="FORTY"
z(5)="FIFTY"
z(6)="SIXTY"
z(7)="SEVENTY"
z(8)="EIGHTY"
z(9)="NINETY"
zr1=z(MID(y,2,1))end function
function dw(y)' 准备数据dim z(5)
z(0)=""
z(1)="THOUSAND"
z(2)="MILLION"
z(3)="BILLION"
dw=z(y)end functionfunction w2(y)' 用来制作2位数字转英文
if MID(y,2,1)="0" then' 判断是否小于10
value=zr3(y)
elseif MID(y,2,1)="1" then' 判断是否在10到20之间
value=zr2(y)
elseif MID(y,3,1)="0" then' 为去掉尾空格,判断是否为大于20小于100的能被10整除的数
value=zr1(y)
else
value=zr1(y)+" "+zr3(y)' 加上10位到个位的空格
end if
w2=value
end functionfunction w3(y)' 用来制作3位数字转英文
if MID(y,1,1)="0" then' 判断是否小于100
value=w2(y)
elseif MID(y,2,2)="00" then' 判断是否能被100整除
value=zr4(y)+" "+"HUNDRED"
else
value=zr4(y)+" "+"HUNDRED"+" "+"AND"+" "+w2(y)' 不能整除的要后面加"AND"
end if
w3=value
end functionfunction make(x)
z=instr(1,x,".",1)' 取小数点位置
if z<>0 then' 判断有无小数
lstr=mid(x,1,z-1)' 取小数点左边字串
rstr=mid(x,z+1,2)' 取小数点右边字串
else
lstr=x' 如果没有小数
end if
lstrev=StrReverse(lstr)' 对左边的字串取反字串
dim a(5)' 定义5个字串变量用来存放解析出的三位一组的字串
select case len(lstrev) mod 3' 字串长度不能被整除,需补齐
case "1"
lstrev=lstrev+"00"
case "2"
lstrev=lstrev+"0"
end select
lm=""' 用来存放转换后的整数部分
for i=0 to len(lstrev)/3-1' 计算有多少个三位
a(i)=StrReverse(mid(lstrev,3*i+1,3))' 截取第1个三位
if a(i)<>"000" then' 用来避免这种情况"1000000=ONE MILLION THOUSAND ONLY"
if i<>0 then
lm=w3(a(i))+" "+dw(i)+" "+lm' 用来加上"THOUSAND OR MILLION OR BILLION"
else
lm=w3(a(i))' 防止i=0时"lm=w3(a(i))+" "+dw(i)+" "+lm"多加两个尾空格
end if
else
lm=w3(a(i))+lm
end if
NEXT
xs=""' 用来存放转换后的小数部分
if z<>0 then
xs="AND CENTS"+" "+w2("$"+rstr)+" "' 小数部分存在时转换小数部分
end if
make=lm+" "+xs+"ONLY"' 最后结果,不要忘记加上ONLY
end function
//将阿拉伯数字转成英文字串
//------------------------
function num2ceng(strArabic:string):string;//不带小数点英文转换中文
const
sw:array[2..9]of string=('twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety');
gw:array[1..19] of string=('one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen');
exp:array[1..4] of string=('','thousand','million','billion');
var
t,j:integer;
ts:string;
function readu1000(ss:string):string;
var
t,code:integer;
begin
result := '';
while ss[1]='0' do
begin
delete(ss,1,1);
if length(ss)=0 then exit;//控制全是0情况
end;
if length(ss)=3 then
begin
appendstr(result,gw[ord(ss[1])-ord('0')]);
appendstr(result,' hundred ');
delete(ss,1,1);
end;
while ss[1]='0' do
begin
delete(ss,1,1);
if length(ss)=0 then exit;
end;
if length(ss)<>0 then
if result <> '' then appendstr(result,'and ');
if (glb = 1) and (t1<>1) then //超过百位时候处理最后3位
if result='' then appendstr(result,'and ');
begin
val(ss,t,code);
if t<20 then result :=result+gw[t]
else if t mod 10=0 then result:=result+sw[t div 10]
else result := result+sw[trunc(t/10)]+'-'+gw[t mod 10];
end;
end;
begin
result :='Say ';
t := pos('.',strArabic);
if t=0 then t:=length(strArabic)+1;
while (t mod 3<>1)do
begin
t:=t+1;
strArabic:='0'+ strArabic;
end;
t1:=(t-1) div 3;
for glb:=t1 downto 1 do
begin
ts:='';
for j:=1 to 3 do
begin
ts:=ts+ strArabic[1];
delete(strArabic,1,1);
end;
result := result + readu1000(ts);
if ts<>'000' then result := result+' '+exp[glb]+' ';
end;
if length(strArabic)<>0 then
begin
delete(strArabic,1,1);
appendstr(result,'and ');
result :=result + readu1000(strArabic);
end;
end;
function num2cengnum(strArabic:string):string;
const
gw:array[1..10] of string =('0','one','two','three','four','five','six','seven','eight','nine');
var
p,i,j,x:integer;
s:string;
begin
result := '';
s := strarabic;
p := pos('.',strarabic);
if p = 0 then
begin
result := num2ceng(strarabic)+'Only';
exit;
end
else
begin
i := length(s)-p;//计算小数点后面有几位
delete(strarabic,p,i+1);//删除小数点后面数字
result := num2ceng(strarabic)+'Point';
end;
for x:=1 to i do //转换小数点后面数字
begin
j:= strtoint(copy(s,p+x,1));
case j of
0: result := result +' '+gw[1];
1: result := result +' '+gw[2];
2: result := result +' '+gw[3];
3: result := result +' '+gw[4];
4: result := result +' '+gw[5];
5: result := result +' '+gw[6];
6: result := result +' '+gw[7];
7: result := result +' '+gw[8];
8: result := result +' '+gw[9];
9: result := result +' '+gw[10];
end;
end;
end;
{ }
{ Number to letters unit version 1.0 }
{ }
{ copyright (C) Dylan Thomas 2000 }
{ }
{ License: No significant restrictions. }
{ }
{ Language: US. English }
{ }
{**************************************************}unit NumberToLetters;interface{varCalls: Integer;} //Use to keep track of the number of recursive calls(* This function returns the written equivalent of a number. *)
function NumToLetters(Number: Real): string;implementation
uses SysUtils;typeTNumberStr = string[13];const
Numbers: array[1..19] of TNumberStr = (one, two, three, four,
five, six, seven, eight, nine, ten, eleven, twelve,
thirteen, fourteen, fifteen, sixteen, seventeen, eighteen,
nineteen);Tenths: array[1..9] of TNumberStr = (ten, twenty, thirty, forty,
fifty, sixty, seventy, eighty, ninety);ErrorString = not in valid range;Min = 1.00;
Max = 4294967295.99;function NumToLetters(Number: Real): string;function RecurseNumber(N: LongWord): string;
begin
{Inc(Calls);} //Use to keep track of the number of recursive calls
case N of
1..19:
Result := Numbers[N];
20..99:
Result := Tenths[N div 10] + + RecurseNumber(N mod 10);
100..999:
Result := Numbers[N div 100] + hundred + RecurseNumber(N mod 100);
1000..999999:
Result := RecurseNumber(N div 1000) + thousand +
RecurseNumber(N mod 1000);
1000000..999999999: Result := RecurseNumber(N div 1000000) + million
+ RecurseNumber(N mod 1000000);
1000000000..4294967295: Result := RecurseNumber(N div 1000000000) +
billion + RecurseNumber(N mod 1000000000);
end; {Case N of}
end; {RecurseNumber}begin
{Calls := 0;} //Use to keep track of the number of recursive calls
if (Number >= Min) and (Number <= Max) then
begin
Result := RecurseNumber(Round(Int(Number)));
{Added for cents in a currency value}
if not(Frac(Number) = 0.00) then
Result := Result + and + IntToStr(Round(Frac(Number) * 100)) +
/100;
end
else
raise ERangeError.CreateFmt(%g + ErrorString + %g..%g,
[Number, Min, Max]);
end;{NumToLetters}end.