各位,在VF中怎么把小写金额转为大写啊,急用,谢谢拉!
这是之前的方法,但是不正确。
se2=""
se2=alltrim(str(se1,10,2))
selen=len(se2)
ds1=space(2)
ds2=space(2)
ds3=space(2)
ds4=space(2)
ds5=space(2)
ds6=space(2)
ds7=space(2)
ds=""
if selen=8
ds1=dx(subs(se2,1,1))
ds2=dx(subs(se2,2,1))
ds3=dx(subs(se2,3,1))
ds4=dx(subs(se2,4,1))
ds5=dx(subs(se2,5,1))
ds6=dx(subs(se2,7,1))
ds7=dx(subs(se2,8,1))
ds="¥"+ds1+"万"+ds2+"仟"+ds3+"佰"+ds4+"拾"+ds5+"元"+ds6+"角"+ds7+"分"
endif
if selen=7
ds2=dx(subs(se2,1,1))
ds3=dx(subs(se2,2,1))
ds4=dx(subs(se2,3,1))
ds5=dx(subs(se2,4,1))
ds6=dx(subs(se2,6,1))
ds7=dx(subs(se2,7,1))
ds="¥"+ds2+"仟"+ds3+"佰"+ds4+"拾"+ds5+"元"+ds6+"角"+ds7+"分"
endif
if selen=6
ds3=dx(subs(se2,1,1))
ds4=dx(subs(se2,2,1))
ds5=dx(subs(se2,3,1))
ds6=dx(subs(se2,5,1))
ds7=dx(subs(se2,6,1))
ds="¥"+ds3+"佰"+ds4+"拾"+ds5+"元"+ds6+"角"+ds7+"分"
endif
if selen=5
ds4=dx(subs(se2,1,1))
ds5=dx(subs(se2,2,1))
ds6=dx(subs(se2,4,1))
ds7=dx(subs(se2,5,1))
ds="¥"+ds4+"拾"+ds5+"元"+ds6+"角"+ds7+"分"
endif
if selen=4.and.val(subs(se2,1,1))>0
ds5=dx(subs(se2,1,1))
ds6=dx(subs(se2,3,1))
ds7=dx(subs(se2,4,1))
ds="¥"+ds5+"元"+ds6+"角"+ds7+"分"
endif
if selen=4.and.subs(se2,1,1)="0".and.val(subs(se2,3,1))>0
ds6=dx(subs(se2,3,1))
ds7=dx(subs(se2,4,1))
ds="¥"+ds6+"角"+ds7+"分"
endif
if selen=4.and.subs(se2,1,1)="0".and.val(subs(se2,3,1))=0.and.val(subs(se2,4,1))>0
ds7=dx(subs(se2,4,1))
ds="¥"+ds7+"分"
endif
**************
function dx
parameter se3
if se3="1"
se11="壹"
endif
if se3="2"
se11="贰"
endif
if se3="3"
se11="叁"
endif
if se3="4"
se11="肆"
endif
if se3="5"
se11="伍"
endif
if se3="6"
se11="陆"
endif
if se3="7"
se11="柒"
endif
if se3="8"
se11="捌"
endif
if se3="9"
se11="玖"
endif
if se3="0"
se11="零"
endif
return se11
------解决方案--------------------------------------------------------
- VBScript code
如何将金额由小写变为大写?*----------------------------------1、编写如下函数。该函数的返回值能够舍去数字之间的零,比较准确,符合会计准则,比较适合打印银行存单等。*----以下代码存入一个dx.prg中,即建立自定义函数----*PARAMETERS nAmountPRIVATE ALL LIKE L_*L_S1='零壹贰叁肆伍陆柒捌玖'L_S2='亿仟佰拾万仟佰拾亿仟佰拾万仟佰拾元角分'nAmount=LTRIM(STR(nAmount*100,LEN(L_S2)/2))L_LEN=LEN(nAmount)L_SS2=RIGH(L_S2,2*L_LEN)L_DX=''L_0JS=0 &&连续零的个数L_N=0DO WHILE L_N<L_LEN L_N=L_N+1 L_SZ=SUBSTR(nAmount,L_N,1) L_SZ=SUBSTR(L_S1,2*VAL(L_SZ)+1,2) L_DW=SUBSTR(L_SS2,2*L_N-1,2) IF L_SZ='零' L_SZ='' DO CASE CASE L_DW$'亿元' CASE L_DW='万' IF RIGH(L_DX,2)='亿' L_DW='' ENDIF OTHERWISE L_DW='' ENDCASE L_0JS=L_0JS+1 ELSE IF L_0JS>0 L_SZ='零'+L_SZ ENDIF L_0JS=0 ENDIF L_DX=L_DX+L_SZ+L_DWENDDOL_DX=L_DX+IIF(RIGH(nAmount,1)='0','整','')RETURN L_DX*----调用方式为----*?dx(124.22)2、编写如下函数。该函数的返回值比较适合于一些单据的填空式打印,如增值税发票等。PARAMETERS nAmount,IsDWnDZS=STRTRAN(ALLTRIM(STR(nAmount,18,2)),".","") &&把小数点去掉cHZDX="零壹贰叁肆伍陆柒捌玖"cDW="分角元拾佰仟万拾佰仟亿拾佰仟万拾佰仟亿"cRMBDX=""nCd=LEN(nDZS)FOR i=1 TO LEN(nDZS) cNumbers=SUBSTRC(cHZDX,INT(VAL(SUBSTR(nDZS,I,1))+1),1) && 数字转换 IF IsDW=1 &&如果要单位 cDWs=SUBSTRC(cDW,nCd,1) ELSE cDWs=SPACE(0) &&不要单位的情况下 ENDIF cRMBDX=cRMBDX+cNumbers+cDWS nCd=nCd-1ENDFOR RETURN cRMBDX3、*----调用方式为----*?camount(123)FUNCTION Camount parameter Mamount MyAmount=alltrim(str(abs(Mamount)*100,11,0)) temp=len(alltrim(MyAmount)) chr_amount='' For i = 1 TO temp MYmemo=val(subs(MyAmount, temp-i+1, 1)) chr_amount =subs("零壹贰叁肆伍陆柒捌玖", MYmemo*2+1, 2)+subs("分角圆拾佰仟万拾佰仟亿", i*2-1, 2)+ chr_amount EndFor chr_amount=iif(Mamount<0,'负'+chr_amount,chr_amount) return chr_amountendFUNC4、*处理9万亿以下的数字没有问题.在接近10万亿的时候,部分会有错误结果...*----调用方式为----*?chandx(123)PROCEDURE chandx PARAMETERS mmje &&输入变量:数字型,小于9万亿,大于-9万亿 PRIVATE dx,aa,i dx=IIF(mmje<0,'负','') aa=ROUND(ABS(mmje)*100,0) FOR i=LEN(ALLTRIM(STR(aa,15)))-1 TO 0 STEP -1 dx=dx+SUBS('零壹贰叁肆伍陆柒捌玖',INT(ROUND(aa/10^i,10))*2+1,2)+SUBS('分角元拾佰仟万拾佰仟亿拾佰仟万',i*2+1,2) aa=MOD(aa,10^i) ENDFOR dx=STRTRAN(STRTRAN(STRTRAN(STRTRAN(STRTRAN(dx,'零仟','零'),'零佰','零'),'零拾','零'),'零角','零'),'零分','整') dx=STRTRAN(STRTRAN(STRTRAN(STRTRAN(STRTRAN(dx,'零零','零'),'零零','零'),'零亿','亿'),'零万','万'),'零元','元')RETURN IIF(dx='整','零元整',STRTRAN(STRTRAN(dx,'亿万','亿'),'零整','整'))5、中文货币转化函数支持16位有效数字的任意金额,16位以上也能支持,但只是从高位起16位以后的被四舍五入了,与会计规范写法基本一致(请教过专业会计)大家放心用吧。*----调用方式为----*?TransformMoney(123)FUNCTION TransformMoneyLPARAMETER lnmoneyLOCAL lnolddecimallnolddecimal=SET("decimal")SET DECIMAL TO 6IF TYPE("lnmoney")<>"N" RETURN ""ENDIFLOCAL lcstr1,lcstr2lcstr1="分角元拾佰仟万拾佰仟亿拾佰仟万拾佰仟万拾佰仟亿拾佰仟万"lcstr2="零壹贰叁肆伍陆柒捌玖"LOCAL lnremain,lnlen,lnnum,lcsign,lcmoneyIF lnmoney<0 lcsign="负" lnmoney=0-lnmoneyELSE lcsign=""ENDIFlnmoney=ROUND(lnmoney,2)IF lnmoney=0 lcmoney="零元整" SET DECIMAL TO lnolddecimal RETURN lcmoneyENDIFlnmoney=lnmoney*100lnremain=lnmoneylnlen=INT(LOG10(lnmoney))+1lcmoney=""FOR i=lnlen TO 1 STEP -1 IF i<>1 lnnum=MOD(FLOOR(lnmoney/(10**(i-1))),10) ELSE lnnum=MOD(ROUND(lnmoney/(10**(i-1)),0),10) ENDIF lnremain=lnremain-lnnum*10**(i-1) IF lnnum<>0 lcmoney=lcmoney+SUBSTR(lcstr2,lnnum*2+1,2) lcmoney=lcmoney+SUBSTR(lcstr1,(i-1)*2+1,2) ELSE IF MOD(i,4)=3 lcmoney=lcmoney+SUBSTR(lcstr1,(i-1)*2+1,2) ENDIF lcmoney=lcmoney+SUBSTR(lcstr2,lnnum*2+1,2) ENDIF lcmoney=STRTRAN(lcmoney,"零零","零") lcmoney=STRTRAN(lcmoney,"零零","零") lcmoney=STRTRAN(lcmoney,"零元","元") lcmoney=STRTRAN(lcmoney,"零万","万") lcmoney=STRTRAN(lcmoney,"零亿","亿") lcmoney=STRTRAN(lcmoney,"亿万","亿零") IF LIKE("*元零??角*",lcmoney) lcmoney=STRTRAN(lcmoney,"元零","元") ENDIF IF LIKE("*万零??仟*",lcmoney) lcmoney=STRTRAN(lcmoney,"万零","万") ENDIF IF LIKE("*亿零??仟*",lcmoney) lcmoney=STRTRAN(lcmoney,"亿零","亿") ENDIF IF i>1 AND i<4 AND lnremain=0 OR (i=1 AND lnnum=0) lcmoney=lcmoney+"整" lcmoney=STRTRAN(lcmoney,"零整","整") EXIT ENDIFENDFORIF RIGHT(lcmoney,2)=="零" lcmoney=LEFT(lcmoney,LEN(lcmoney)-2)ENDIFlcmoney=lcsign+lcmoneySET DECIMAL TO lnolddecimalRETURN lcmoneyENDFUNC6、*----调用方式为----*?UPPERRMB(10021.56)FUNCTION UPPERRMBPARAMETER RMBPRIVATE UNIT, NUMBER, I, RETVARUNIT = '分角圆拾佰仟万拾佰仟亿拾佰仟万拾佰仟'NUMBER = '零壹贰叁肆伍陆柒捌玖'RMB = INT(RMB*100+0.5)RETVAR = ''DO WHILE RMB>0 RETVAR = SUBSTR(NUMBER,2*(MOD(RMB,10))+1,2)+LEFT(UNIT,2)+RETVAR RMB = INT(RMB/10) UNIT = SUBSTR(UNIT,3)ENDDORETVAR = STRTRAN(RETVAR,'零仟','零')RETVAR = STRTRAN(RETVAR,'零佰','零')RETVAR = STRTRAN(RETVAR,'零拾','零')RETVAR = STRTRAN(RETVAR,'零角','零')DO WHILE '零零'$RETVAR RETVAR = STRTRAN(RETVAR,'零零','零')ENDDORETVAR = STRTRAN(RETVAR,'零亿','亿')RETVAR = STRTRAN(RETVAR,'零万','万')RETVAR = STRTRAN(RETVAR,'亿万','亿零')RETVAR = STRTRAN(RETVAR,'零零','零')RETVAR = STRTRAN(RETVAR,'零圆','圆')RETVAR = STRTRAN(RETVAR,'零分','整')RETVAR = IIF(LEN(RETVAR)=0,'零圆整',RETVAR)RETURN RETVAR7、*----调用方式为----*?ntoc(10021.56)FUNC ntocPARA numLOCAL string,string1,string2IF num<100000000RETU ntoc2(num)ENDIFSTRING=allt(str(num,20,2))string1=right(string,11)string2=substr(string,1,len(string)-11)string1=ntoc2(val(string1))string2=ntoc2(val(string2))STRING=left(string2,len(string2)-4)+''''亿''''+string1IF right(string,6)=''''零元正''''STRING=substr(string,1,len(string)-6)+''''元正''''ENDIFRETU stringFUNC ntoc2PARAMETERS NUMPRIV NUM,CHAR,POSI,I,STR,TEMP,iiDIMENSION CHAR(10),POSI(7)**wait wind str(num,14,2)CHAR(1) =''''壹''''CHAR(2) =''''贰''''CHAR(3) =''''叁''''CHAR(4) =''''肆''''CHAR(5) =''''伍''''CHAR(6) =''''陆''''CHAR(7) =''''柒''''CHAR(8) =''''捌''''CHAR(9) =''''玖''''CHAR(10)=''''零''''POSI(1) =''''分''''POSI(2) =''''角''''POSI(3) =''''元''''POSI(4) =''''拾''''POSI(5) =''''佰''''POSI(6) =''''仟''''POSI(7) =''''万''''STR=''''''''IF NUM>=100000000 &&一亿RETURN ''''*********''''ENDIFNUM=NUM*100I=1ii=1lasttemp=1DO WHILE NUM>=1NUM=NUM/10TEMP=INT((NUM-INT(NUM))*10)I=IIF(I=8,4,I)IF temp#0 &&char(iif(temp=0,10,temp))#''''零''''STR=CHAR(IIF(TEMP=0,10,TEMP))+POSI(I)+STRELSEIF(i=3)STR=''''元''''+strENDIFIF (i=7)STR=''''万''''+strENDIFENDIFIF temp=0.and.i>1.and.lasttemp#temp.and.;left(str,2)#''''元''''.and.left(str,2)#''''万''''STR=''''零''''+strENDIFI=I+1ii=ii+1lasttemp=tempENDDOIF right(str,2)#''''分''''STR=str+''''正''''ENDIFIF str=''''正''''STR=''''零元正''''ENDIFRETURN STR