数字小写到英文大写的转换

发表于:2007-06-30来源:作者:点击数: 标签:
建议入精华,方便需要写英文软件的朋友! % 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
建议入精华,方便需要写英文软件的朋友!

<%

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

%>


原文转自:http://www.ltesting.net