您的位置:程序门 -> vb -> 基础类



数字转换大写,不是金额转换,是阿拉伯数字转换为大写,含小数位


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


数字转换大写,不是金额转换,是阿拉伯数字转换为大写,含小数位
发表于:2007-01-12 12:48:07 楼主
数字转换大写,不是金额转换,是阿拉伯数字转换为大写,含小数位
发表于:2007-01-12 15:26:471楼 得分:0
就是把数字一位一位的用中文读出来,如0对零,1对壹?
发表于:2007-02-08 15:19:002楼 得分:0
前两天刚刚写了一个,楼主赶上趟了:

private   function   entoch(byval   en   as   string)   as   string
dim   num   as   double
dim   i   as   long
dim   l   as   long
dim   m   as   long
dim   n   as   long
dim   tmp   as   double
dim   cnum(23)   as   string
dim   tmpnum()   as   string           '´æ·åõûêý²¿·öµäêý×ö£¬°´4î»·ö¿ª
dim   tmpnum1()   as   string       '´æ·åõûêý²¿·öºíð¡êý²¿·öµäêý×ö
dim   tmpstr   as   string
en   =   trim(en)
if   not   isnumeric(en)   then
      entoch   =   "êý×öêäèë´íîó "
      exit   function
end   if

cnum(0)   =   "áã "
cnum(1)   =   "ò¼ "
cnum(2)   =   "·¡ "
cnum(3)   =   "èþ "
cnum(4)   =   "ëá "
cnum(5)   =   "îé "
cnum(6)   =   "â½ "
cnum(7)   =   "æâ "
cnum(8)   =   "°æ "
cnum(9)   =   "¾á "
cnum(10)   =   " "
cnum(11)   =   "ê° "
cnum(12)   =   "°û "
cnum(13)   =   "çª "
cnum(14)   =   "ô² "
cnum(15)   =   "íò "
cnum(16)   =   "òú "
cnum(17)   =   "õ× "
cnum(18)   =   "¾© "
cnum(19)   =   "·ö "
cnum(20)   =   "½ç "
cnum(21)   =   "áã "
cnum(22)   =   "õû "
cnum(23)   =   "¸º "
en   =   trim(en)
en   =   replace(en,   ", ",   " ")   '襳ý¶ººå·ö¸ô·û
tmpnum1   =   split(en,   ". ")     'µãµ½õûêý²¿·öºíð¡êý²¿·ö
if   ubound(tmpnum1)   >   1   then
      entoch   =   "´íîóµäêý×öêäè룬¶àóúò»¸öð¡êýµã "
      exit   function
end   if

i   =   len(tmpnum1(0))           '¼æëãõûêýî»êý
if   left(tmpnum1(0),   1)   =   "- "   then
      tmpnum1(0)   =   right(tmpnum1(0),   i   -   1)
      en   =   cnum(23)
      i   =   i   -   1
else
      en   =   " "
end   if
if   i   >   20   then
      entoch   =   "êý×ö¹ý´ó£¬îþ·¨¼æëã "
      exit   function
end   if

m   =   i
l   =   ((i   -   1)   \   4)
redim   tmpnum(l)                   '°´4î»·ö¿ªõûêý¶î
tmpstr   =   tmpnum1(0)
for   n   =   0   to   l
      tmpnum(n)   =   right(tmpstr,   4)
      m   =   m   -   4
      if   m   >   0   then   tmpstr   =   left(tmpnum1(0),   m)
next

for   i   =   l   to   0   step   -1     '·­òëõûêý²¿·ö
      tmp   =   val(tmpnum(i))
      for   m   =   3   to   0   step   -1
            n   =   (tmp   \   (10   ^   m))   mod   10
            entoch   =   entoch   &   cnum(n)   &   cnum(m   +   10)
      next
      entoch   =   entoch   &   cnum(i   +   14)
next

for   l   =   11   to   13       'ðþõýáã窣¬áã°û£¬áãê°£½¡·áã
      entoch   =   replace(entoch,   cnum(0)   &   cnum(l),   cnum(0))
      entoch   =   replace(entoch,   cnum(0)   &   cnum(0),   cnum(0))     'ðþõýáãá㣽¡·áã
next
for   n   =   0   to   2
      for   l   =   15   to   18     'ðþõýáãíòáãòúáãõ×á㾩£½¡·íò£¬òú£¬õ×£¬¾©
            entoch   =   replace(entoch,   cnum(0)   &   cnum(l),   cnum(l))
      next
      'ðþõý¾©òú£¬¾©õ×£¬¾©íò£¬õ×òú£¬õ×íò£¬òúíò£½¡·¾©á㣬õ×á㣬òúáã
      for   i   =   18   to   16   step   -1
            for   l   =   i   -   1   to   15   step   -1
                  entoch   =   replace(entoch,   cnum(i)   &   cnum(l),   cnum(i)   &   cnum(0))
            next
      next
      entoch   =   replace(entoch,   cnum(0)   &   cnum(0),   cnum(0))     'ðþõýáãá㣽¡·áã
next

if   left(entoch,   1)   =   cnum(0)   then   entoch   =   right(entoch,   len(entoch)   -   1)     'ðþõý¿ªí·áã
entoch   =   replace(entoch,   cnum(0)   &   cnum(14),   cnum(14))       'ðþõýáãô²£½¡·ô²

if   ubound(tmpnum1)   >   0   then   '·­òëð¡êý²¿·ö
      tmpstr   =   left(tmpnum1(1)   &   "0 ",   2)
      tmp   =   val(tmpstr)
      if   tmp   =   0   then
            entoch   =   entoch   &   cnum(22)
      else
            for   m   =   1   to   0   step   -1
                  n   =   (tmp   \   (10   ^   m))   mod   10
                  entoch   =   entoch   &   cnum(n)   &   cnum(m   +   19)
            next
      end   if
else
      entoch   =   entoch   &   cnum(22)
end   if
entoch   =   replace(entoch,   cnum(0)   &   cnum(19),   " ")     'ðþõýáã·ö£½¡· " "
entoch   =   replace(entoch,   cnum(0)   &   cnum(20),   cnum(0))     'ðþõýáã½ç£½¡·áã

entoch   =   en   &   entoch
end   function

将上面这段函数拷贝到你的程序里。
调用的时候:
entoch   "222299393338299.33 "
最长支持20位整数位长度的数字(如果有这么多钱的话)
用得好就给分吧
发表于:2007-02-08 15:22:033楼 得分:0
中间的乱码是vb中的注释,好像拷贝过来就不行了,vb对中文的支持还是不尽人意
发表于:2007-02-08 15:28:224楼 得分:0
20位,,,就是日圆也可以排首富了。
发表于:2007-02-08 15:30:145楼 得分:0
我也正想要这个呢?试试看,走运了!
发表于:2007-02-08 15:30:306楼 得分:0
up   一下
发表于:2007-02-08 15:33:167楼 得分:0
试了不行
发表于:2007-02-08 15:46:198楼 得分:0
晕了,还是因为中文没转过来,估计大家翻译出来的是乱码。我这里改正乱码再贴,大家试用一下,有什么小错的自己改改就行了:


private   function   entoch(byval   en   as   string)   as   string
dim   num   as   double
dim   i   as   long
dim   l   as   long
dim   m   as   long
dim   n   as   long
dim   tmp   as   double
dim   cnum(23)   as   string
dim   tmpnum()   as   string          
dim   tmpnum1()   as   string      
dim   tmpstr   as   string
en   =   trim(en)
if   not   isnumeric(en)   then
      entoch   =   "这个明显不是数字,别蒙了 "
      exit   function
end   if

cnum(0)   =   "铃 "
cnum(1)   =   "医 "
cnum(2)   =   "尔 "
cnum(3)   =   "伞 "
cnum(4)   =   "斯 "
cnum(5)   =   "舞 "
cnum(6)   =   "瘤 "
cnum(7)   =   "奇 "
cnum(8)   =   "霸 "
cnum(9)   =   "酒 "
cnum(10)   =   " "
cnum(11)   =   "屎 "
cnum(12)   =   "摆 "
cnum(13)   =   "牵 "
cnum(14)   =   "园 "
cnum(15)   =   "碗 "
cnum(16)   =   "议 "
cnum(17)   =   "照 "
cnum(18)   =   "精 "
cnum(19)   =   "粉 "
cnum(20)   =   "脚 "
cnum(21)   =   "陵 "
cnum(22)   =   "蒸 "
cnum(23)   =   "妇 "
en   =   trim(en)
en   =   replace(en,   ", ",   " ")  
tmpnum1   =   split(en,   ". ")    
if   ubound(tmpnum1)   >   1   then
      entoch   =   错误数字,多于一个小数点 "
      exit   function
end   if

i   =   len(tmpnum1(0))          
if   left(tmpnum1(0),   1)   =   "- "   then
      tmpnum1(0)   =   right(tmpnum1(0),   i   -   1)
      en   =   cnum(23)
      i   =   i   -   1
else
      en   =   " "
end   if
if   i   >   20   then
      entoch   =   "数字太长,无法计算 "
      exit   function
end   if

m   =   i
l   =   ((i   -   1)   \   4)
redim   tmpnum(l)                  
tmpstr   =   tmpnum1(0)
for   n   =   0   to   l
      tmpnum(n)   =   right(tmpstr,   4)
      m   =   m   -   4
      if   m   >   0   then   tmpstr   =   left(tmpnum1(0),   m)
next

for   i   =   l   to   0   step   -1    
      tmp   =   val(tmpnum(i))
      for   m   =   3   to   0   step   -1
            n   =   (tmp   \   (10   ^   m))   mod   10
            entoch   =   entoch   &   cnum(n)   &   cnum(m   +   10)
      next
      entoch   =   entoch   &   cnum(i   +   14)
next

for   l   =   11   to   13      
      entoch   =   replace(entoch,   cnum(0)   &   cnum(l),   cnum(0))
      entoch   =   replace(entoch,   cnum(0)   &   cnum(0),   cnum(0))  
next
for   n   =   0   to   2
      for   l   =   15   to   18    
            entoch   =   replace(entoch,   cnum(0)   &   cnum(l),   cnum(l))
      next
            for   i   =   18   to   16   step   -1
            for   l   =   i   -   1   to   15   step   -1
                  entoch   =   replace(entoch,   cnum(i)   &   cnum(l),   cnum(i)   &   cnum(0))
            next
      next
      entoch   =   replace(entoch,   cnum(0)   &   cnum(0),   cnum(0))    
next

if   left(entoch,   1)   =   cnum(0)   then   entoch   =   right(entoch,   len(entoch)   -   1)    
entoch   =   replace(entoch,   cnum(0)   &   cnum(14),   cnum(14))      

if   ubound(tmpnum1)   >   0   then  
      tmpstr   =   left(tmpnum1(1)   &   "0 ",   2)
      tmp   =   val(tmpstr)
      if   tmp   =   0   then
            entoch   =   entoch   &   cnum(22)
      else
            for   m   =   1   to   0   step   -1
                  n   =   (tmp   \   (10   ^   m))   mod   10
                  entoch   =   entoch   &   cnum(n)   &   cnum(m   +   19)
            next
      end   if
else
      entoch   =   entoch   &   cnum(22)
end   if
entoch   =   replace(entoch,   cnum(0)   &   cnum(19),   " ")    
entoch   =   replace(entoch,   cnum(0)   &   cnum(20),   cnum(0))    

entoch   =   en   &   entoch
end   function

使用方法:
sub   command1_click()
msgbox   entoch( "19234723298432497.92 ")
end   sub
发表于:2007-02-08 15:46:329楼 得分:0
不行我就吃下去
发表于:2007-02-08 15:56:5710楼 得分:0
楼上的将那中文字改一下吧,谢谢!有几个猜不出来是什么!
发表于:2007-02-08 15:58:3511楼 得分:0
cnum(18)   =   "精 "       是什么呢?
cnum(19)   =   "粉 "     是   “分”
cnum(20)   =   "脚 "     是     “角”
cnum(21)   =   "陵 "     是什么呢?
发表于:2007-02-08 16:02:5512楼 得分:0
public   function   convertnum2rmb(num)   as   string
       
        dim   money1   as   string
        dim   tn   as   long
        dim   k1   as   string
        dim   k2   as   string
        dim   k3   as   string
        dim   st1   as   string
        dim   t1   as   string

        if   num   =   0   then
                convertnum2rmb   =   "零圆 "
                exit   function
        end   if
       
        if   num   <   0   then
                convertnum2rmb   =   "负 "   +   convertnum2rmb(abs(num))
                exit   function
        end   if
       
'         if   money1   =   " "   then   exit   function
        money1   =   trim(str(num))
        tn   =   instr(money1,   ". ")     '小数位置
        k1   =   " "
        if   tn   <>   0   then
                st1   =   right(money1,   len(money1)   -   tn)
                if   st1   <>   " "   then
                        t1   =   left(st1,   1)
                        st1   =   right(st1,   len(st1)   -   1)
                        if   t1   <>   "0 "   then
                                k1   =   k1   +   changnum(val(t1))   +   "角 "
                        end   if
                        if   st1   <>   " "   then
                                t1   =   left(st1,   1)
                                k1   =   k1   +   changnum(val(t1))   +   "分 "
                        end   if
                end   if
                st1   =   left(money1,   tn   -   1)
        else
                st1   =   money1
        end   if

        k2   =   " "
        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                k2   =   changnum(val(t1))   +   k2
        end   if

        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                if   t1   <>   "0 "   then
                        k2   =   changnum(val(t1))   +   "拾 "   +   k2
                else
                        if   left(k2,   1)   <>   "零 "   then   k2   =   "零 "   +   k2
                end   if
        end   if

        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                if   t1   <>   "0 "   then
                        k2   =   changnum(val(t1))   +   "佰 "   +   k2
                else
                        if   left(k2,   1)   <>   "零 "   then   k2   =   "零 "   +   k2
                end   if
        end   if

        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                if   t1   <>   "0 "   then
                        k2   =   changnum(val(t1))   +   "仟 "   +   k2
                else
                        if   left(k2,   1)   <>   "零 "   then   k2   =   "零 "   +   k2
                end   if
        end   if

        k3   =   " "
        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                k3   =   changnum(val(t1))   +   k3
        end   if


        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                if   t1   <>   "0 "   then
                        k3   =   changnum(val(t1))   +   "拾 "   +   k3
                else
                        if   left(k3,   1)   <>   "零 "   then   k3   =   "零 "   +   k3
                end   if
        end   if

        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                if   t1   <>   "0 "   then
                        k3   =   changnum(val(t1))   +   "佰 "   +   k3
                else
                        if   left(k3,   1)   <>   "零 "   then   k3   =   "零 "   +   k3
                end   if
        end   if

        if   st1   <>   " "   then
                t1   =   right(st1,   1)
                st1   =   left(st1,   len(st1)   -   1)
                if   t1   <>   "0 "   then
                        k3   =   changnum(val(t1))   +   "仟 "   +   k3
                end   if
        end   if
        if   right(k2,   1)   =   "零 "   then   k2   =   left(k2,   len(k2)   -   1)
        if   len(k3)   >   0   then
                if   right(k3,   1)   =   "零 "   then   k3   =   left(k3,   len(k3)   -   1)
                k3   =   k3   &   "万 "
        end   if

        convertnum2rmb   =   iif(k3   &   k2   =   " ",   k1,   k3   &   k2   &   "元 "   &   k1)
       
end   function

private   function   changnum(num   as   integer)   as   string
       
        select   case   num
                case   0
                        changnum   =   "零 "
                case   1
                        changnum   =   "壹 "
                case   2
                        changnum   =   "贰 "
                case   3
                        changnum   =   "叁 "
                case   4
                        changnum   =   "肆 "
                case   5
                        changnum   =   "伍 "
                case   6
                        changnum   =   "陆 "
                case   7
                        changnum   =   "柒 "
                case   8
                        changnum   =   "捌 "
                case   9
                        changnum   =   "玖 "
        end   select

end   function
发表于:2007-02-08 16:10:5813楼 得分:0
楼主想要的是非金额转换
发表于:2007-02-08 16:19:3314楼 得分:0
兆   =》万亿
京   =》万兆
核   =》万京     (应该是   "土 "字旁的,我打不出来)
发表于:2007-02-08 16:20:3915楼 得分:0
咱们中国人就是牛4位一轮的,哪象老外,才3位就憋不住要整个新词了。
发表于:2007-02-08 16:25:1816楼 得分:0
呵呵,不要生气,这样不好。
发表于:2007-02-08 16:27:0717楼 得分:0
非金额转换也简单,将那个“圆”“角”“分”和“整”都该成“”就行了。
还有就是将tmpstr   =   left(tmpnum1(1)   &   "0 ",   2)改成tmpstr   =   tmpnum1(1)应该就行了
不过没有测试过,楼主自己改
发表于:2007-02-08 16:35:1518楼 得分:0
楼上写的不错
public   function   rmbchange(txtje   as   double)   as   string
    on   error   goto   err1
                    dim   i           as   long                   '循环变量
                    dim   k           as   long                   '记录整数位循环位置
                    dim   nc           as   string           '输入金额       '
                    dim   chrnum           as   string               '保存从字串中取出的数字
                    dim   c1           as   string           '中文大写单位
                    dim   c2           as   string           '中文角分
                    dim   c3           as   string           '中文大写数字
                    dim   zheng           as   string               '整数部分
                    dim   xiao           as   string                   '小数部分
                       
                    nc   =   trim(format(txtje,   "##0.00 "))
                    c1   =   "仟佰拾万仟佰拾亿仟佰拾万仟佰拾元 "
                    c2   =   "角分 "
                    c3   =   "玖捌柒陆伍肆叁贰壹 "
                    if   nc   =   0   then
                                    daxie   =   "零元整 "
                                    exit   function
                    end   if
                       
                    daxie   =   " "
                    zheng   =   mid(nc,   1,   (len(nc)   -   3))
                    xiao   =   mid(nc,   (len(zheng)   +   2),   2)
                    if   val(xiao)   <>   0   then
                                    for   i   =   len(xiao)   to   1   step   -1
                                                    chrnum   =   mid(xiao,   i,   1)
                                                    if   chrnum   <>   0   then
                                                                    daxie   =   mid(c2,   i,   1)   &   daxie
                                                                    daxie   =   mid(c3,   (len(c3)   -   chrnum   +   1),   1)   &   daxie
                                                    else
                                                                    if   i   =   1   then
                                                                                    daxie   =   "零 "   &   daxie
                                                                    end   if
                                                    end   if
                                    next   i
                    end   if
                       
                    k   =   0
                    if   val(zheng)   <>   0   then
                                    daxie   =   "元 "   &   daxie
                                    for   i   =   len(zheng)   to   1   step   -1
                                                    if   (len(zheng)   -   i)   =   4   then
                                                                    if   val(mid(zheng,   len(zheng)   -   4,   1))   =   0   and   _
                                                                                mid(daxie,   1,   1)   <>   "零 "   and   _
                                                                                mid(daxie,   1,   1)   <>   "元 "   then
                                                                                    daxie   =   "零 "   &   daxie
                                                                    end   if
                                                                       
                                                                    if   len(zheng)   > =   9   then
                                                                                    if   val(mid(zheng,   len(zheng)   -   7,   4))   =   0   then
                                                                                                    daxie   =   daxie
                                                                                    else
                                                                                                    daxie   =   "万 "   &   daxie
                                                                                    end   if
                                                                    else
                                                                                    daxie   =   "万 "   &   daxie
                                                                    end   if
                                                    elseif   (len(zheng)   -   i)   =   8   then
                                                                    if   val(mid(zheng,   len(zheng)   -   8,   1))   =   0   and   _
                                                                                mid(daxie,   1,   1)   <>   "零 "   and   _
                                                                                mid(daxie,   1,   1)   <>   "元 "   then
                                                                                    daxie   =   "零 "   &   daxie
                                                                    end   if
                                                                       
                                                                    daxie   =   "亿 "   &   daxie
                                                    elseif   (len(zheng)   -   i)   =   12   then
                                                                    if   val(mid(zheng,   len(zheng)   -   12,   1))   =   0   and   _
                                                                                mid(daxie,   1,   1)   <>   "零 "   and   _
                                                                                mid(daxie,   1,   1)   <>   "元 "   then
                                                                                    daxie   =   "零 "   &   daxie
                                                                    end   if
                                                                       
                                                                    daxie   =   "万 "   &   daxie
                                                    end   if
                                                    chrnum   =   mid(zheng,   i,   1)
                                                    if   chrnum   <>   0   then
                                                                    if   i   =   len(zheng)   then
                                                                                    daxie   =   mid(c3,   (len(c3)   -   chrnum   +   1),   1)   &   daxie
                                                                    else
                                                                                    if   (len(zheng)   -   i)   <>   4   and   _
                                                                                                (len(zheng)   -   i)   <>   8   and   _
                                                                                                (len(zheng)   -   i)   <>   12   then
                                                                                                    daxie   =   mid(c1,   (len(c1)   -   k),   1)   &   daxie
                                                                                    end   if
                                                                                    daxie   =   mid(c3,   (len(c3)   -   chrnum   +   1),   1)   &   daxie
                                                                    end   if
                                                    else
                                                                    if   mid(daxie,   1,   1)   <>   "元 "   and   _
                                                                                mid(daxie,   1,   1)   <>   "万 "   and   _
                                                                                mid(daxie,   1,   1)   <>   "亿 "   then
                                                                                    if   mid(daxie,   1,   1)   <>   "零 "   then
                                                                                                    daxie   =   "零 "   &   daxie
                                                                                    end   if
                                                                    end   if
                                                end   if
                                                    k   =   k   +   1
                                    next   i
                    end   if
                    if   right(trim(daxie),   1)   <>   "分 "   then
                                    daxie   =   daxie   &   "整 "
                    end   if
       
    exit   function
err1:
'     msgbox   "你输入的数字太长或者格式错误. ",   ,   "***系统 "
    end   function
发表于:2007-02-08 17:36:3219楼 得分:0
用这么麻烦吗
建立一个数字表对照就是了

比如d(0)   =   "零 "
....d(1)= "一 "

然后就是  
str= "3205698 "

dim   i   as   integer
dim   xx   as   string
for   i   =   1   to   len(str)
  xx   =   xx   &   d(val(mid(str,i,1)))
next
发表于:2007-02-08 17:47:2220楼 得分:0
zou_seafarer(颓废程序员^_^)   (   )
用这么麻烦吗
建立一个数字表对照就是了
------------------------------
楼上的到底仔细想过这个问题没有阿。
举个例子你就知道哪里不对了:

1:   10001  
直接转成   壹零零零壹     这个算对么?
而正确的是   壹万零壹
发表于:2007-02-08 17:50:4121楼 得分:0
呵呵,楼上都开始说你(颓废程序员)了,我什么也不说了!
发表于:2007-02-08 18:06:0622楼 得分:0
还是那个什么     ---伞圆伞脚伞粪---读得舒服。。。呵呵。。
发表于:2007-02-08 23:12:3223楼 得分:0
大家是不是被楼主耍了,呵呵,多没露过面

起码你写数字和转换结果,大家才知道你想要什么,还有大小写转换又不是金额,那又是什么,机械转换吗?
发表于:2007-02-09 09:05:0924楼 得分:0
楼主想要的是这样的转换
1563.23=壹仟伍佰陆拾叁点贰叁
发表于:2007-02-09 09:29:0525楼 得分:0
to:wallescai(沧海明月一度,西风残阳无悔.)  
颓废程序员说的是对的,楼主就是要那样的效果,楼主要的不是金额转换而是纯数字转换。
发表于:2007-02-09 09:34:2626楼 得分:0
小改了一下,测试中
非负值,两位小数位
private   function   cchinese(streng   as   string)   as   string
        if   not   isnumeric(streng)   or   streng   like   "*-* "   then
                if   trim(streng)   <>   " "   then   msgbox   "数字格式有误 ",   vbcritical   +   vbokonly,   "错误 "
                cchinese   =   " ":   exit   function
        end   if
        dim   intlen   as   integer,   intcounter   as   integer
        dim   strch   as   string,   strtempch   as   string
        dim   strseqch1   as   string,   strseqch2   as   string
        dim   streng2ch   as   string
        streng2ch   =   "零壹贰叁肆伍陆柒捌玖 "
        strseqch1   =   "   拾佰仟   拾佰仟   拾佰仟   拾佰仟 "
        strseqch2   =   "   万亿兆 "
        streng   =   cstr(format(streng,   "##0.00 "))
        intlen   =   iif(instr(streng,   ". ")   =   0,   len(streng),   instr(streng,   ". ")   -   1)
        for   intcounter   =   1   to   intlen
                strtempch   =   mid(streng2ch,   val(mid(streng,   intcounter,   1))   +   1,   1)
                if   strtempch   =   "零 "   and   intlen   <>   1   then
                        if   mid(streng,   intcounter   +   1,   1)   =   "0 "   or   (intlen   -   intcounter   +   1)   mod   4   =   1   then
                                strtempch   =   " "
                        end   if
                else
                        strtempch   =   strtempch   &   trim(mid(strseqch1,   intlen   -   intcounter   +   1,   1))
                end   if
                if   (intlen   -   intcounter   +   1)   mod   4   =   1   then
                        strtempch   =   strtempch   &   mid(strseqch2,   (intlen   -   intcounter   +   1)   \   4   +   1,   1)
                        if   intcounter   >   3   then
                                if   mid(streng,   intcounter   -   3,   4)   =   "0000 "   then   strtempch   =   left(strtempch,   len(strtempch)   -   1)
                        end   if
                end   if
                strch   =   strch   &   trim(strtempch)
        next

        if   instr(streng,   ". ")   =   0   then
              cchinese   =   strch
              exit   function
        else
              intcounter   =   instr(streng,   ". ")   +   1
              if   val(mid(streng,   intcounter,   1))   =   0   and   val(mid(streng,   intcounter   +   1,   1))   =   0   then
                  cchinese   =   strch
                  exit   function
              else
                  strch   =   strch   &   "点 "
                  for   intcounter   =   instr(streng,   ". ")   +   1   to   len(streng)
                      strch   =   strch   &   mid(streng2ch,   val(mid(streng,   intcounter,   1))   +   1,   1)
                  next   intcounter
                    cchinese   =   strch
              end   if
        end   if
end   function
发表于:2007-02-09 10:52:3727楼 得分:0
to   t2(無藥可救)
颓废程序员说的是对的,楼主就是要那样的效果,楼主要的不是金额转换而是纯数字转换。
-------------------------
请看题目:
...阿拉伯数字转换为大写,含小数位

那就是说按照中文的念法来翻译咯
发表于:2007-02-09 10:54:3228楼 得分:0
to   wallescai(沧海明月一度,西风残阳无悔.)  
请看题目:
...阿拉伯数字转换为大写,含小数位

那就是说按照中文的念法来翻译咯
-----------------------------
请看题目:
...不是金额转换...
发表于:2007-02-09 11:14:5029楼 得分:0
不管怎么说,都是本着助人为乐,互相提高的目的,呵呵!
发表于:2007-02-09 11:17:2630楼 得分:0
用这个试试:
function   chnumstr(num)
strlen=len(num)
for   i=1   to   strlen
select   case   mid(num,i,1)
case   1:chnum= "一 ":case   2:chnum= "二 ":case   3:chnum= "三 ":case   4:chnum= "四 ":case   5:chnum= "五 "
case   6:chnum= "六 ":case   7:chnum= "七 ":case   8:chnum= "八 ":case   9:chnum= "九 ":case   0:chnum= "零 "
end   select
chnumstr=chnumstr&chnum
if   i=strlen-1   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "十 "
if   i=strlen-2   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "百 "
if   i=strlen-3   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "千 "
if   i=strlen-4   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "万 "
if   i=strlen-5   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "十 "
if   i=strlen-6   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "百 "
if   i=strlen-7   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "千 "
if   i=strlen-8   and   mid(num,i,1) <> 0   then   chnumstr=chnumstr& "万 "
next
end   function
发表于:2007-02-09 11:21:3031楼 得分:0
呵呵:
测试如下:输入   85.65
                    输出:八万五千五百六十五
是正确的吗?
发表于:2007-02-09 11:29:5332楼 得分:0
下面的代码不是很周全,提供一个思路吧

function   changnum(num   as   double)   as   string
       
        dim   strnum   as   string,   strnum1   as   string,   strnum2   as   string
        dim   strpos   as   string
        dim   arr()   as   string
        dim   i   as   integer,   j   as   integer
        dim   str   as   string
           
        strpos   =   "点,拾,佰,仟,万,拾,佰,仟,亿,拾,佰,仟,万,兆 "
        arr   =   split(strpos,   ", ")
       
        strnum   =   format(num,   "#.0000 ")
        strnum1   =   left(strnum,   instr(strnum,   ". ")   -   1)
     
        for   i   =   len(strnum1)   to   1   step   -1
                changnum   =   mid(strnum1,   i,   1)   &   arr(j)   &   changnum
                j   =   j   +   1
        next   i
        changnum   =   changnum   &   mid(strnum,   instr(strnum,   ". ")   +   1)
       
        changnum   =   replace(changnum,   "0 ",   "零 ")
        changnum   =   replace(changnum,   "1 ",   "壹 ")
        changnum   =   replace(changnum,   "2 ",   "贰 ")
        changnum   =   replace(changnum,   "3 ",   "叁 ")
        changnum   =   replace(changnum,   "4 ",   "肆 ")
        changnum   =   replace(changnum,   "5 ",   "伍 ")
        changnum   =   replace(changnum,   "6 ",   "陆 ")
        changnum   =   replace(changnum,   "7 ",   "柒 ")
        changnum   =   replace(changnum,   "8 ",   "捌 ")
        changnum   =   replace(changnum,   "9 ",   "玖 ")
        '如果不用转换为中文语法,下面可以注释掉
        changnum   =   replace(changnum,   "零亿 ",   "亿 ")
        changnum   =   replace(changnum,   "零万 ",   "零 ")
        changnum   =   replace(changnum,   "零仟 ",   "零 ")
        changnum   =   replace(changnum,   "零佰 ",   "零 ")
        changnum   =   replace(changnum,   "零拾 ",   "零 ")
        changnum   =   replace(changnum,   "零零零零零零零零 ",   "零 ")
        changnum   =   replace(changnum,   "零零零零零零零 ",   "零 ")
        changnum   =   replace(changnum,   "零零零零零零 ",   "零 ")
        changnum   =   replace(changnum,   "零零零零零 ",   "零 ")
        changnum   =   replace(changnum,   "零零零零 ",   "零 ")
        changnum   =   replace(changnum,   "零零零 ",   "零 ")
        changnum   =   replace(changnum,   "零零 ",   "零 ")
               
end   function
发表于:2007-02-09 12:27:5933楼 得分:0
其实前面几位的程序都是不错的,但都有一个缺点不知道大家发现没有。
那就是都用一个数值型的变量来存放这个要转换的数字。
虽然说使用double类型也可以存放非常大的数字,但是double类型当数字位数很长的时候不是很精确的,最后几位会发生问题。
不信大家可以做一下试验:
private   sub   form_load()
dim   i   as   double
i   =   val( "9876543210987654321 ")
msgbox   i
end   sub
最后的654321变成660000了

而我的程序用的是字符串方式,中间最长的数字才4位(9999)所以不会发生这个问题。
呵呵。


再   to   t2(無藥可救)
请看题目:
...不是金额转换...
--------------------
我当然知道不是金额转换,我只是想请你用通用的中文念一下下面的数字是多少:
10001
如果你念的是一万零一,那就是我对。
如果你念的是一零零零一,ok,那我只能对你表示我的敬意。
发表于:2007-02-09 13:42:3134楼 得分:0
to:wallescai(沧海明月一度,西风残阳无悔.)  
我当然知道不是金额转换,我只是想请你用通用的中文念一下下面的数字是多少:
10001
如果你念的是一万零一,那就是我对。
如果你念的是一零零零一,ok,那我只能对你表示我的敬意。
--------------------------------------------------
不想与你再继续争辩,请问?
“...阿拉伯数字转换为大写,含小数位

那就是说按照中文的念法来翻译咯”

有何根据?阿拉伯数字转换为大写即是一定要用中文念法来读吗?
再请问10001如果是金额请问怎么读?
既然不是要转换为金额,那么也不一定要按金额的读法来转吧!?
现实生活中这样的例子也有很多,并不一定要分出个,拾,佰吧,
比如某样商品的编号是87654,你难道读给别人的时候是说八万七千六百五十四吗?
还是看看楼主到底要的是什么再下定论吧。
发表于:2007-02-09 14:23:0435楼 得分:0
大家都在问:楼主究竟要什么?
我想再问:楼主是什么?会说话吗?
发表于:2007-02-09 15:02:1336楼 得分:0
对症下药
发表于:2007-02-09 23:28:2837楼 得分:0
有兴趣的看看我的贴:

http://community.csdn.net/expert/topicview.asp?id=5349865
发表于:2007-02-10 08:27:2838楼 得分:0
楼主要的是非金额转换,楼上的朋友
发表于:2007-02-13 13:54:4139楼 得分:0
to   t2(無藥可救)  
...
不想与你再继续争辩,请问?
“...阿拉伯数字转换为大写,含小数位

那就是说按照中文的念法来翻译咯”
...
---------------------------------------------
不按照中文念法来翻译,那干吗要翻译成中文大写??
发表于:2007-06-15 11:06:5440楼 得分:0
因为t2的别名是(無藥可救)。just   kidding.
发表于:2007-06-15 13:35:3541楼 得分:0
up
发表于:2007-06-26 07:25:4542楼 得分:0
function   trans(number   as   string)   as   string
    dim   x   as   string,   y   as   string
    x   =   split(number,   ". ")(0)
    const   upcase   =   "○一二三四五六七八九   十百千万十百千万亿十百千万十百千万 "                   '定义汉字
    if   val(x)   > =   10   ^   16   then   msgbox   "数目太大,无法换算!请输入一亿亿以下的数字! ",   64,   "错误提示 ":   exit   function   '只能转换一亿亿以下的数字!
    if   instr(number,   ". ")   >   0   then
    y   =   split(number,   ". ")(1)
    for   i   =   0   to   9
    y   =   replace(y,   i,   mid(upcase,   i   +   1,   1))
    next
    y   =   "点 "   &   y
    end   if
    for   i   =   1   to   len(x)
    trans   =   trans   &   mid(upcase,   mid(x,   i,   1)   +   1,   1)   &   mid(upcase,   len(x)   -   i   +   11,   1)
    next
    trans   =   replace(trans,   "○千 ",   "○ ")
    trans   =   replace(trans,   "○百 ",   "○ ")
    trans   =   replace(trans,   "○十 ",   "○ ")
       
    do   while   instr(trans,   "○○ ")   >   0
    trans   =   replace(trans,   "○○ ",   "○ ")
    loop
    trans   =   replace(trans,   "○亿 ",   "亿 ")
    trans   =   replace(trans,   "○万 ",   "万 ")
if   val(x)   <   20   then   trans   =   replace(trans,   "一十 ",   "十 ")
trans   =   trim(trans)   &   y
    end   function
       
  private   sub   command1_click()
      msgbox   trans( "67454801211.783450980896 ")
    end   sub
发表于:2007-07-05 18:10:3143楼 得分:0
好东东啊