建议入精华,方便需要写英文软件的朋友!
<%
function convertsz(sz)
parameters sz
private xs,sz1,sz2,sz3
if sz > 1000000000 then 超过处理范围提示
convertsz="number is too big" 数字大于10亿,超过处理范围!
exit function
end if
sz=int(sz*100+0.5)/100 小数超过两位四舍五入
xs=((sz-int(sz))*100) mod 100 取小数点后两位有效数字
if xs>0 then
cha=" and"&conv3(xs)&" cents" 转换小数
cha=" and "&xs&" cents"
else
cha=""
end if
sz1=int((sz mod 1000)) sz1为百、十、个3位数字
sz=int(sz/1000) sz为千位以上数字(含千位)
cha=conv3(sz1)&cha 转换(sz1)
if sz>0 then
sz2=(sz mod 1000) sz2为十万、万、千3位数字
sz=int(sz/1000) sz为百万位以上数字(含百万位)
if sz2=0 then
if sz1=0 then (sz2)如果为0,判断在百位之前是否加and
cha=cha
else
cha=" and"&cha
end if
else
cha=conv3(sz2)&" thousand"&cha 如果不为0转换(sz2)
end if
if sz>0 then
sz3=(sz mod 1000) sz3为亿、千万、百万3位数字
cha=conv3(sz3)&" million"&cha 转换(sz3)
end if
end if
cha="dollar"&cha 在转换的结果之前加dollar
return cha
convertsz=cha
end function
function conv3(je)
parameters je
private jews,je1,je2,je3,tmp
if je<=0 then
convertsz=""
exit function
end if
je1=(je mod 10)
je=int(je/10)
if je=0 then 判断数字位数(1-3)并把3位数字分别存放在je1、je2、je3中
jews=1
else
je2=(je mod 10)
je=int(je/10)
if je=0 then
jews=2
else
je3=(je mod 10)
jews=3
end if
end if
if jews=1 then
tmp=conv1(je1) 如果位数为1,直接转换
conv3=tmp
exit function
return tmp
else
if je1+10*je2<20 then 转换20以下数字
tmp=conv1(je1+10*je2)
else 转换20-99数字
if je1=0 then
tmp=conv2(je2)
else
tmp=conv2(je2)&" -"&conv1(je1)
tmp=conv2(je2)&conv1(je1)
end if
end if
if jews=3 then 转换百位数字
if je1+10*je2=0 then
tmp=conv1(je3)&" hundred"
else
if je1+10*je2<20 then
tmp=conv1(je3)&" hundred and"&tmp
else
tmp=conv1(je3)&" hundred"&tmp
end if
end if
end if
conv3=tmp
end if
end function
function conv2(sum)
parameters sum
aaa=""
select case sum
case 2
aaa=" twenty"
case 3
aaa=" thirty"
case 4
aaa=" forty"
case 5
aaa=" fifty"
case 6
aaa=" sixty"
case 7
aaa=" seventy"
case 8
aaa=" eighty"
case 9
aaa=" ninety"
end select
conv2=aaa
end function
function conv1(sum)
parameters sum
aaa=""
select case sum
case 1
aaa=" one"
case 2
aaa=" two"
case 3
aaa=" three"
case 4
aaa=" four"
case 5
aaa=" five"
case 6
aaa=" six"
case 7
aaa=" seven"
case 8
aaa=" eight"
case 9
aaa=" nine"
case 10
aaa=" ten"
case 11
aaa=" eleven"
case 12
aaa=" twelve"
case 13
aaa=" thirteen"
case sum=14
aaa=" fourteen"
case 15
aaa=" fifteen"
case 16
aaa=" sixteen"
case 17
aaa=" seventeen"
case 18
aaa=" eighteen"
case sum=19
aaa=" nineteen"
end select
conv1=aaa
end function
fff=123456789.45
response.write fff&"<br>"
xx=convertsz(fff)
response.write xx
%>
