欢迎光临
我们一直在努力

数字转英文(货币)大写-.NET教程,数据库应用

建站超值云服务器,限时71元/月

功能模块:数字转英文(货币)大写

public function numbertostring(number as double) as string

调用形式:debug.print numbertostring(1234.32)

说明:最大支持12位数字,小数点后精确两位

程序:杨鑫光(volitation)

dim strno(19) as string

dim unit(8) as string

dim strtens(9) as string

public function numbertostring(number as double) as string

dim str as string, beforepoint as string, afterpoint as string, tmpstr as string

dim point as integer

dim nbit as integer

dim curstring as string

call init

//开始处理

str = cstr(round(number, 2))

str = number

if instr(1, str, ".") = 0 then

beforepoint = str

afterpoint = ""

else

beforepoint = left(str, instr(1, str, ".") – 1)

afterpoint = right(str, len(str) – instr(1, str, "."))

end if

if len(beforepoint) > 12 then

numbertostring = "too big."

exit function

end if

str = ""

do while len(beforepoint) > 0

nnumlen = len(beforepoint)

if nnumlen mod 3 = 0 then

curstring = left(beforepoint, 3)

beforepoint = right(beforepoint, nnumlen – 3)

else

curstring = left(beforepoint, (nnumlen mod 3))

beforepoint = right(beforepoint, nnumlen – (nnumlen mod 3))

end if

nbit = len(beforepoint) / 3

tmpstr = decodehundred(curstring)

if (beforepoint = string(len(beforepoint), "0") or nbit = 0) and len(curstring) = 3 then

if cint(left(curstring, 1)) <> 0 and cint(right(curstring, 2)) <> 0 then

tmpstr = left(tmpstr, instr(1, tmpstr, unit(4)) + len(unit(4))) & unit(8) & " " & right(tmpstr, len(tmpstr) – (instr(1, tmpstr, unit(4)) + len(unit(4))))

else if cint(left(curstring, 1)) <> 0 and cint(right(curstring, 2)) = 0 then

tmpstr = unit(8) & " " & tmpstr

end if

end if

if nbit = 0 then

str = trim(str & " " & tmpstr)

else

str = trim(str & " " & tmpstr & " " & unit(nbit))

end if

if left(str, 3) = unit(8) then str = trim(right(str, len(str) – 3))

if beforepoint = string(len(beforepoint), "0") then exit do

debug.print str

loop

beforepoint = str

if len(afterpoint) > 0 then

afterpoint = unit(6) & " " & decodehundred(afterpoint) & " " & unit(7)

else

afterpoint = unit(5)

end if

numbertostring = beforepoint & " " & afterpoint

end function

private function decodehundred(hundredstring as string) as string

dim tmp as integer

if len(hundredstring) > 0 and len(hundredstring) <= 3 then

select case len(hundredstring)

case 1

tmp = cint(hundredstring)

if tmp <> 0 then decodehundred = strno(tmp)

case 2

tmp = cint(hundredstring)

if tmp <> 0 then

if (tmp < 20) then

decodehundred = strno(tmp)

else

if cint(right(hundredstring, 1)) = 0 then

decodehundred = strtens(int(tmp / 10))

else

decodehundred = strtens(int(tmp / 10)) & "-" & strno(cint(right(hundredstring, 1)))

end if

end if

end if

case 3

if cint(left(hundredstring, 1)) <> 0 then

decodehundred = strno(cint(left(hundredstring, 1))) & " " & unit(4) & " " & decodehundred(right(hundredstring, 2))

else

decodehundred = decodehundred(right(hundredstring, 2))

end if

case else

end select

end if

end function

private sub init()

if strno(1) <> "one" then

strno(1) = "one"

strno(2) = "two"

strno(3) = "three"

strno(4) = "four"

strno(5) = "five"

strno(6) = "six"

strno(7) = "seven"

strno(8) = "eight"

strno(9) = "nine"

strno(10) = "ten"

strno(11) = "eleven"

strno(12) = "twelve"

strno(13) = "thirteen"

strno(14) = "fourteen"

strno(15) = "fifteen"

strno(16) = "sixteen"

strno(17) = "seventeen"

strno(18) = "eighteen"

strno(19) = "nineteen"

strtens(1) = "ten"

strtens(2) = "twenty"

strtens(3) = "thirty"

strtens(4) = "forty"

strtens(5) = "fifty"

strtens(6) = "sixty"

strtens(7) = "seventy"

strtens(8) = "eighty"

strtens(9) = "ninety"

unit(1) = "thousand" 第一个三位

unit(2) = "million" 第二个三位

unit(3) = "billion" 第三个三位

unit(4) = "hundred"

unit(5) = "only"

unit(6) = "point"

unit(7) = "cent"不是货币的话,把此值赋空

unit(8) = "and"

end if

end sub

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 数字转英文(货币)大写-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章