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



人民币大写转换的问题,请高手解决,谢谢!


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


人民币大写转换的问题,请高手解决,谢谢!
发表于:2007-06-12 11:20:43 楼主
我在支票程序中用如下语句转化大写,一般情况下没什么问题,但是到千位和十位都是零的时候,千位的零不显示。结果被银行退回来了,郁闷啊。举例:30801,我的软件显示为“叁万捌佰零壹圆整”,银行认为是“叁万零捌佰零壹圆整”。
跪求各位高手帮我看看下面的语句。谢谢!     我知道问题出在倒数第五行,但不知道怎么在现有结构基础上修改,请高手帮忙!    

        c1   =   "零壹贰叁肆伍陆柒捌玖 "
        c2   =   "拾佰仟 "
       

private   function   rmb(s   as   currency)   as   string
        dim   str0   as   string,   strfen   as   string,   stryuan   as   string,   strwan   as   string,   stryi   as   string
        dim   strwanyi   as   string
        dim   strtemp   as   string
        dim   lpoint   as   integer
        dim   flag   as   boolean
     
       
        if   abs(s)   <   0.01   then   rmb   =   "零 ":   exit   function
       
        str0   =   ltrim(str$(abs(s)))
        lpoint   =   instrrev(str0,   ". ")
       
        if   lpoint   =   0   then
                str0   =   str0   &   ".00 "
        else
                str0   =   left(str0   &   "00 ",   lpoint   +   2)
        end   if
       
        strfen   =   right(str0,   2)
        stryuan   =   left(str0,   len(str0)   -   3)
        if   val(stryuan)   =   0   then   flag   =   true
       
        if   len(stryuan)   >   4   then
                strwan   =   left(stryuan,   len(stryuan)   -   4)
                stryuan   =   right(stryuan,   4)
        end   if
       
        if   len(strwan)   >   4   then
                stryi   =   left(strwan,   len(strwan)   -   4)
                strwan   =   right(strwan,   4)
        end   if
       
        if   len(stryi)   >   4   then
                strwanyi   =   left(stryi,   len(stryi)   -   4)
                stryi   =   right(stryi,   4)
        end   if
       
        if   right(strfen,   1)   =   "0 "   then
                strtemp   =   "整 "
                if   left(strfen,   1)   <>   "0 "   then   strtemp   =   mid(c1,   val(left(strfen,   1))   +   1,   1)   &   "角整 "
        else
                if   left(strfen,   1)   =   "0 "   then
                        if   flag   then
                                strtemp   =   mid(c1,   val(right(strfen,   1))   +   1,   1)   &   "分 "
                        else
                                strtemp   =   "零 "   &   mid(c1,   val(right(strfen,   1))   +   1,   1)   &   "分 "
                        end   if
                else
                        strtemp   =   mid(c1,   val(left(strfen,   1))   +   1,   1)   &   "角 "   &   mid(c1,   val(right(strfen,   1))   +   1,   1)   &   "分 "
                end   if
        end   if
       
        if   stryuan   <>   " "   then   strtemp   =   change(stryuan)   &   "元 "   &   strtemp
        if   strwan   <>   " "   and   val(strwan)   <>   0   then   strtemp   =   change(strwan)   &   "万 "   &   strtemp
        if   stryi   <>   " "   then   strtemp   =   change(stryi)   &   "亿 "   &   strtemp
       
        if   strwanyi   <>   " "   then   strtemp   =   change(strwanyi)   &   "万 "   &   strtemp
       
        rmb   =   strtemp
        exit   function
end   function

private   function   change(s   as   string)   as   string
        dim   c   as   string,   str   as   string
        dim   l   as   integer,   i   as   integer
        dim   f1   as   boolean,   f2   as   boolean
        str   =   " "
        f1   =   false
        f2   =   false
        l   =   len(s)
        if   right(s,   1)   <>   "0 "   then
                str   =   mid(c1,   val(right(s,   1))   +   1,   1)
                f1   =   true
        end   if
        for   i   =   l   -   1   to   1   step   -1
                c   =   mid(s,   i,   1)
                if   c   <>   "0 "   then
                        str   =   mid(c1,   val(c)   +   1,   1)   &   mid(c2,   l   -   i,   1)   &   str
                        f1   =   true
                else
                        if   f1   and   (not   f2)   then   str   =   "零 "   &   str:   f2   =   true
                end   if
        next   i
        change   =   str
end   function

发表于:2007-06-12 17:20:571楼 得分:0
不记得从哪里得到的函数了,仅供参考
?up( "30801 ")
叁万零捌佰零壹元
*************************************************
function   up(dxs   as   string)   as   string
'检测为空时
  if   trim(dxs)   =   " "   then
        msgbox   "没有数字,不能转换! ",   vbokonly   +   32
        exit   function
end   if
    dim   sw   as   integer,   szp   as   integer,   szup   as   integer,   tempstr   as   string,   dxstr   as   string
        sw   =   len(trim(dxs))
        szp   =   instr(1,   trim(dxs),   ". ")
if   szp   =   0   then
      dim   i   as   integer
          for   i   =   1   to   sw
                  tempstr   =   right(trim(dxs),   i)
                  tempstr   =   left(tempstr,   1)
                  tempstr   =   converts(tempstr)
                  select   case   i
                      case   1
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "元 "
                                      else
                                    tempstr   =   tempstr   +   "元 "
                              end   if
                      case   2
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                else
                                    tempstr   =   tempstr   +   "拾 "
                              end   if
                      case   3
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "佰 "
                              end   if
                        case   4
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "仟 "
                              end   if
                        case   5
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "万 "
                                      else
                                    tempstr   =   tempstr   +   "万 "
                              end   if
                        case   6
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "拾 "
                              end   if
                        case   7
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "佰 "
                              end   if
                        case   8
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "仟 "
                              end   if
                        case   9
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "亿 "
                                      else
                                    tempstr   =   tempstr   +   "亿 "
                              end   if
                  end   select
        dim   tempa   as   string
                tempa   =   left(trim(dxstr),   1)
        if   tempstr   =   "零 "   then
            select   case   tempa
              case   "零 "
                        dxstr   =   dxstr
              case   "元 "
                        dxstr   =   dxstr
              case   "万 "
                        dxstr   =   dxstr
              case   "亿 "
                        dxstr   =   dxstr
              case   else
                        dxstr   =   tempstr   +   dxstr
            end   select
            else
              dxstr   =   tempstr   +   dxstr
        end   if
          next
    else
        for   i   =   1   to   szp   -   1
                  tempstr   =   right(trim(dxs),   i   +   (sw   -   szp   +   1))
                  tempstr   =   left(tempstr,   1)
                  tempstr   =   converts(tempstr)
                  select   case   i
                      case   1
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "元 "
                                      else
                                    tempstr   =   tempstr   +   "元 "
                              end   if
                      case   2
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                else
                                    tempstr   =   tempstr   +   "拾 "
                              end   if
                      case   3
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "佰 "
                              end   if
                        case   4
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "仟 "
                              end   if
                        case   5
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "万 "
                                      else
                                    tempstr   =   tempstr   +   "万 "
                              end   if
                        case   6
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "拾 "
                              end   if
                        case   7
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "佰 "
                              end   if
                        case   8
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "零 "
                                      else
                                    tempstr   =   tempstr   +   "仟 "
                              end   if
                        case   9
                              if   tempstr   =   "零 "   then
                                    tempstr   =   "亿 "
                                      else
                                    tempstr   =   tempstr   +   "亿 "
                              end   if
                        case   else
                            '超过999999999时自动删除
                            tempstr   =   " "
                  end   select
                tempa   =   left(trim(dxstr),   1)
        if   tempstr   =   "零 "   then
            select   case   tempa
              case   "零 "
                        dxstr   =   dxstr
              case   "元 "
                        dxstr   =   dxstr
              case   "万 "
                        dxstr   =   dxstr
              case   "亿 "
                        dxstr   =   dxstr
              case   else
                        dxstr   =   tempstr   +   dxstr
            end   select
            else
              dxstr   =   tempstr   +   dxstr
        end   if
          next
'计算小数
      dim   dxstrx   as   string,   xstr   as   string
            xstr   =   right(trim(dxs),   sw   -   szp)
                for   i   =   1   to   sw   -   szp
                  tempstr   =   left(xstr,   i)
                  tempstr   =   right(tempstr,   1)
                  tempstr   =   converts(tempstr)
                  select   case   i
                      case   1
                        if   tempstr   =   "零 "   then
                              tempstr   =   " "
                              else
                              tempstr   =   tempstr   +   "角 "
                        end   if
                      case   2
                        if   tempstr   =   "零 "   then
                              tempstr   =   " "
                              else
                              tempstr   =   tempstr   +   "分 "
                              end   if
                        case   else
                            '超过两位小数时,自动删除
                            tempstr   =   " "
                  end   select
                dxstrx   =   dxstrx   +   tempstr
          next
          dxstr   =   dxstr   +   dxstrx
end   if
        up   =   dxstr
end   function

function   converts(numstr   as   string)   as   string
        select   case   val(numstr)
            case   0
                converts   =   "零 "
            case   1
                converts   =   "壹 "
            case   2
                converts   =   "贰 "
            case   3
                converts   =   "叁 "
            case   4
                converts   =   "肆 "
            case   5
                converts   =   "伍 "
            case   6
                  converts   =   "陆 "
            case   7
                  converts   =   "柒 "
            case   8
                  converts   =   "捌 "
            case   9
                  converts   =   "玖 "
        end   select
end   function
发表于:2007-06-12 19:11:542楼 得分:0
参考:
http://community.csdn.net/expert/topic/5291/5291672.xml?temp=.4437372
发表于:2007-06-12 19:13:213楼 得分:0
另参考:
http://community.csdn.net/expert/topic/5290/5290745.xml?temp=.6544153

我写的一个财务软件里面用的,直接扒下来的函数,还热的呢
发表于:2007-06-12 20:25:384楼 得分:0
http://www.egooglet.com/static_html/200511121314332748admin.html
源码
发表于:2007-06-12 21:22:075楼 得分:0
0.02
银行正规怎么叫的?
发表于:2007-06-12 21:48:586楼 得分:0
0.12
银行怎么叫:either   元壹角贰分   or   零元壹角贰分   or   壹角贰分
发表于:2007-06-12 22:40:367楼 得分:0
晕阿,这倒提醒我了,我写那段代码的时候倒没有想到用这么小的数字来测试.
我们的财务老是不停提醒我: "数字要大,非常非常大... "
发表于:2007-06-13 12:12:558楼 得分:0
楼上~~~~~~,呵呵

你们是不是还都没有考虑用户会输入     23,532,329.03     这样的数字呢?
我是见识过,专程出差去解决,原来是这样想像不到的事情.
发表于:2007-06-13 12:27:439楼 得分:0
以前写的一段代码,crystal   report语法的

local   stringvar   array   achr:=[ "壹 ", "贰 ", "叁 ", "肆 ", "伍 ", "陆 ", "柒 ", "捌 ", "玖 "];
local   stringvar   array   acng:=[ " ", "拾 ", "佰 ", "仟 ", "萬 ", "拾 ", "佰 ", "仟 ", "亿 ", "拾 "];
local   stringvar   array   acnl:=[ "角 ", "分 "];
local   stringvar   stotalamt;
local   stringvar   slc;
local   stringvar   src;
local   stringvar   sresult;
local   numbervar   i;

stotalamt:=replace(totext(cdbl({apupurheadreff.ptot}),2), ", ", " ");
//stotalamt:= "1020001.08 ";

slc:=strreverse(split(stotalamt, ". ",2)[1]);
src:=split(stotalamt, ". ",2)[2];

sresult:= " ";
for   i:=1   to   length(slc)   do

        if   slc[i]= "0 "   then
        (      
                if   right(sresult,1) <> "零 "   and   sresult <> " "   then
                        sresult:=sresult   &   "零 ";  
        )                      
        else
                sresult:=sresult   &   acng[i]   &   achr[int(tonumber(slc[i]))];
);        

if   sresult <> " "   then
        sresult:=strreverse(sresult)   &   "元 ";

for   i:=1   to   length(src)   do

        if   src[i] <> "0 "   then
                sresult:=sresult   &   achr[int(tonumber(src[i]))]   &   acnl[i];
);
"合计: "   &   sresult   &   "整 ";

发表于:2007-06-13 12:55:1810楼 得分:0
entoch( "23,   532,   329.03 ")=贰仟叁佰伍拾叁万贰仟叁佰贰拾玖元零叁分

发表于:2007-06-13 12:57:4311楼 得分:0
code:
http://community.csdn.net/expert/topicview3.asp?id=5291672
http://community.csdn.net/expert/topicview3.asp?id=5290745
发表于:2007-06-13 13:00:3412楼 得分:0
这么多人帮你回答,lz应加分。呵呵。
发表于:2007-06-14 09:40:1013楼 得分:0
其实数据中有逗号什么的都很容易解决,一个replace就叫他消失了.
发表于:2007-06-14 09:46:0014楼 得分:0
code:
http://community.csdn.net/expert/topicview3.asp?id=5291672
http://community.csdn.net/expert/topicview3.asp?id=5290745

我测试过,上面的链接中的code可以用,稍微改一点。
entoch( "23,   532,   329.03 ")=贰仟叁佰伍拾叁万贰仟叁佰贰拾玖元零叁分
entoch支持“,”

good   luck!
发表于:2007-06-14 11:43:0915楼 得分:0
其实数据中有逗号什么的都很容易解决,一个replace就叫他消失了.
============================================================
对,完全可以通过前期的预处理把数据整理成简单有效的格式
发表于:2007-06-14 20:41:2216楼 得分:0
发表于:2007-06-14 20:59:3117楼 得分:0
发表于:2007-06-15 10:11:2618楼 得分:0
恩,把我原来的代码也修改好了,象   0.20这样的数字,就直接翻译成贰角
至于数字中间的逗号,其实最简单不过了,一个replace就消失了
发表于:2007-06-15 11:04:4619楼 得分:0
wallescai 's   code   works.i   suggest   lz   checking   his   code.
发表于:2007-06-15 11:08:0920楼 得分:0
to   wallescai:
please   update   your   code   for   lz   and   us.
发表于:2007-06-25 01:57:4221楼 得分:0
多年前写的,正好满足你的要求:
http://blog.csdn.net/northwolves/archive/2004/05/30/19599.aspx

function   daxie(money   as   string)   as   string   '
dim   x   as   string,   y   as   string
const   zimu   =   ".sbqwsbqysbqwsbq "   '定义位置代码
const   letter   =   "0123456789sbqwy.zjf "   '定义汉字缩写
const   upcase   =   "零壹贰叁肆伍陆柒捌玖拾佰仟萬億圆整角分 "   '定义大写汉字
dim   temp   as   string
temp   =   money
if   instr(temp,   ". ")   >   0   then   temp   =   left(temp,   instr(temp,   ". ")   -   1)

if   len(temp)   >   16   then   msgbox   "数目太大,无法换算!请输入一亿亿以下的数字 ",   64,   "错误提示 ":   exit   function   '只能转换一亿亿元以下数目的货币!

x   =   format(money,   "0.00 ")   '格式化货币
y   =   " "
for   i   =   1   to   len(x)   -   3
y   =   y   &   mid(x,   i,   1)   &   mid(zimu,   len(x)   -   2   -   i,   1)
next
if   right(x,   3)   =   ".00 "   then
y   =   y   &   "z "                     '***元整
else
  y   =   y   &   left(right(x,   2),   1)   &   "j "   &   right(x,   1)   &   "f "           '*元*角*分
  end   if
y   =   replace(y,   "0q ",   "0 ")   '避免零千(如:40200肆萬零千零贰佰)
y   =   replace(y,   "0b ",   "0 ")   '避免零百(如:41000肆萬壹千零佰)
y   =   replace(y,   "0s ",   "0 ")   '避免零十(如:204贰佰零拾零肆)

do   while   y   <>   replace(y,   "00 ",   "0 ")
y   =   replace(y,   "00 ",   "0 ")   '避免双零(如:1004壹仟零零肆)
loop
y   =   replace(y,   "0y ",   "y ")   '避免零億(如:210億           贰佰壹十零億)
y   =   replace(y,   "0w ",   "w ")   '避免零萬(如:210萬           贰佰壹十零萬)
y   =   iif(len(x)   =   5   and   left(y,   1)   =   "1 ",   right(y,   len(y)   -   1),   y)   '避免壹十(如:14壹拾肆;10壹拾)
y   =   iif(len(x)   =   4,   replace(y,   "0. ",   " "),   replace(y,   "0. ",   ". "))   '避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分)

for   i   =   1   to   19
y   =   replace(y,   mid(letter,   i,   1),   mid(upcase,   i,   1))   '大写汉字
next
daxie   =   y
end   function

private   sub   command1_click()
msgbox   daxie( "30801 ")     '   return:   叁万零捌佰零壹圆整
end   sub


快速检索

最新资讯
热门点击