遇到1008.08元时会转换成 壹仟零捌元捌分。 正确应该是 壹仟零捌元零捌分
先在这里感谢了
s_1="零壹贰叁肆伍陆柒捌玖"
s_2="仟佰拾万仟佰拾元角分"
s_3=88888888.88
s_4=STR(dd*100,10)
i=1
mm=" "
DO WHILE i<=10
s_5=SUBSTR(s_4,i,1)
IF s_5<>" "
s_6=SUBSTR(s_1,VAL(s_5)*2+1,2)
s_7=SUBSTR(s_2,i*2-1,2)
IF s_5="0".AND.i<>4.AND.i<>8
s_7=""
ENDIF
if i<9
IF (SUBSTR(s_4,i,2)="00").OR.(s_5="0".AND.(i=4.OR.i=8.OR.i=10))
s_6=""
ENDIF
else
IF (SUBSTR(s_4,i,2)="0").OR.(s_5="0".AND.(i=4.OR.i=8.OR.i=10))
s_6=""
ENDIF
endif
mm=mm+s_6+s_7
if i<9
IF SUBSTR(s_4,i,1)="0".AND.SUBSTR(s_4,i+1,1)<>"0".AND.(i=4.OR.i=8)
mm=mm+"零"
ENDIF
endif
ENDIF
i=i+1
ENDDO
IF s_5="0"
mm=mm+"整"
5 个解决方案
#1
? AmtInWord(1008.08)
FUNCTION AmtInWord( tnAmount )
LOCAL nAmt, cRet, ii
m.cRet = IIF( m.tnAmount < 0, '负' , '' )
m.nAmt = ROUND( ABS( m.tnAmount ) * 100, 0 )
FOR m.ii = LEN( ALLTRIM( STR( m.nAmt, 15 ))) - 1 TO 0 STEP -1
m.cRet = m.cRet + SUBSTR( '零壹贰叁肆伍陆柒捌玖', ;
INT( ROUND( m.nAmt / 10 ^ m.ii, 10 ))*2 + 1, 2 ) + ;
SUBSTR( '分角元拾佰仟万拾佰仟亿拾佰仟万', m.ii * 2 + 1, 2 )
m.nAmt = MOD( m.nAmt, 10 ^ m.ii )
ENDFOR
m.cRet = STRTRAN( STRTRAN( STRTRAN( STRTRAN( STRTRAN( m.cRet, ;
'零仟', '零' ), '零佰', '零' ), '零拾', '零' ), ;
'零角', '零' ), '零分', '整' )
m.cRet = STRTRAN( STRTRAN( STRTRAN( STRTRAN( STRTRAN( m.cRet, ;
'零零', '零' ), '零零', '零' ), '零亿', '亿' ), ;
'零万', '万' ), '零元', '元' )
m.cRet = IIF( m.cRet == '整', '零元整', ;
STRTRAN( STRTRAN( m.cRet, '亿万', '亿' ), '零整', '整' ))
RETURN m.cRet
ENDFUNC
#3
自从来此论坛,学到了不少东西,学习了!
#4
一直使用的函数。
**金额小写转换大写
FUNC cash
PARAMETER RMB
on error return '数据出错'
PRIVATE FH,UNIT, NUMBER, I, RETVAR
UNIT = '分角圆拾佰仟万拾佰仟亿拾佰仟'
NUMBER = '零壹贰叁肆伍陆柒捌玖'
FH=''
IF RMB<0
RMB=-RMB
FH='负'
ENDI
IF RMB>=1000000000000
RETURN '数据溢出'
ENDI
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)
ENDDO
RETVAR = STRTRAN(RETVAR,'零仟','零')
RETVAR = STRTRAN(RETVAR,'零佰','零')
RETVAR = STRTRAN(RETVAR,'零拾','零')
RETVAR = STRTRAN(RETVAR,'零角','零')
DO WHILE '零零'$RETVAR
RETVAR = STRTRAN(RETVAR,'零零','零')
ENDDO
RETVAR = STRTRAN(RETVAR,'零亿','亿')
RETVAR = STRTRAN(RETVAR,'零万','万')
RETVAR = STRTRAN(RETVAR,'亿万','亿零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零圆','圆零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零分','整')
RETVAR = IIF(RETVAR=='','零圆整',RETVAR)
on error
RETURN FH+RETVAR
**金额小写转换大写
FUNC cash
PARAMETER RMB
on error return '数据出错'
PRIVATE FH,UNIT, NUMBER, I, RETVAR
UNIT = '分角圆拾佰仟万拾佰仟亿拾佰仟'
NUMBER = '零壹贰叁肆伍陆柒捌玖'
FH=''
IF RMB<0
RMB=-RMB
FH='负'
ENDI
IF RMB>=1000000000000
RETURN '数据溢出'
ENDI
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)
ENDDO
RETVAR = STRTRAN(RETVAR,'零仟','零')
RETVAR = STRTRAN(RETVAR,'零佰','零')
RETVAR = STRTRAN(RETVAR,'零拾','零')
RETVAR = STRTRAN(RETVAR,'零角','零')
DO WHILE '零零'$RETVAR
RETVAR = STRTRAN(RETVAR,'零零','零')
ENDDO
RETVAR = STRTRAN(RETVAR,'零亿','亿')
RETVAR = STRTRAN(RETVAR,'零万','万')
RETVAR = STRTRAN(RETVAR,'亿万','亿零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零圆','圆零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零分','整')
RETVAR = IIF(RETVAR=='','零圆整',RETVAR)
on error
RETURN FH+RETVAR
#5
我也有遇到这样的问题。。。
#1
? AmtInWord(1008.08)
FUNCTION AmtInWord( tnAmount )
LOCAL nAmt, cRet, ii
m.cRet = IIF( m.tnAmount < 0, '负' , '' )
m.nAmt = ROUND( ABS( m.tnAmount ) * 100, 0 )
FOR m.ii = LEN( ALLTRIM( STR( m.nAmt, 15 ))) - 1 TO 0 STEP -1
m.cRet = m.cRet + SUBSTR( '零壹贰叁肆伍陆柒捌玖', ;
INT( ROUND( m.nAmt / 10 ^ m.ii, 10 ))*2 + 1, 2 ) + ;
SUBSTR( '分角元拾佰仟万拾佰仟亿拾佰仟万', m.ii * 2 + 1, 2 )
m.nAmt = MOD( m.nAmt, 10 ^ m.ii )
ENDFOR
m.cRet = STRTRAN( STRTRAN( STRTRAN( STRTRAN( STRTRAN( m.cRet, ;
'零仟', '零' ), '零佰', '零' ), '零拾', '零' ), ;
'零角', '零' ), '零分', '整' )
m.cRet = STRTRAN( STRTRAN( STRTRAN( STRTRAN( STRTRAN( m.cRet, ;
'零零', '零' ), '零零', '零' ), '零亿', '亿' ), ;
'零万', '万' ), '零元', '元' )
m.cRet = IIF( m.cRet == '整', '零元整', ;
STRTRAN( STRTRAN( m.cRet, '亿万', '亿' ), '零整', '整' ))
RETURN m.cRet
ENDFUNC
#2
#3
自从来此论坛,学到了不少东西,学习了!
#4
一直使用的函数。
**金额小写转换大写
FUNC cash
PARAMETER RMB
on error return '数据出错'
PRIVATE FH,UNIT, NUMBER, I, RETVAR
UNIT = '分角圆拾佰仟万拾佰仟亿拾佰仟'
NUMBER = '零壹贰叁肆伍陆柒捌玖'
FH=''
IF RMB<0
RMB=-RMB
FH='负'
ENDI
IF RMB>=1000000000000
RETURN '数据溢出'
ENDI
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)
ENDDO
RETVAR = STRTRAN(RETVAR,'零仟','零')
RETVAR = STRTRAN(RETVAR,'零佰','零')
RETVAR = STRTRAN(RETVAR,'零拾','零')
RETVAR = STRTRAN(RETVAR,'零角','零')
DO WHILE '零零'$RETVAR
RETVAR = STRTRAN(RETVAR,'零零','零')
ENDDO
RETVAR = STRTRAN(RETVAR,'零亿','亿')
RETVAR = STRTRAN(RETVAR,'零万','万')
RETVAR = STRTRAN(RETVAR,'亿万','亿零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零圆','圆零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零分','整')
RETVAR = IIF(RETVAR=='','零圆整',RETVAR)
on error
RETURN FH+RETVAR
**金额小写转换大写
FUNC cash
PARAMETER RMB
on error return '数据出错'
PRIVATE FH,UNIT, NUMBER, I, RETVAR
UNIT = '分角圆拾佰仟万拾佰仟亿拾佰仟'
NUMBER = '零壹贰叁肆伍陆柒捌玖'
FH=''
IF RMB<0
RMB=-RMB
FH='负'
ENDI
IF RMB>=1000000000000
RETURN '数据溢出'
ENDI
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)
ENDDO
RETVAR = STRTRAN(RETVAR,'零仟','零')
RETVAR = STRTRAN(RETVAR,'零佰','零')
RETVAR = STRTRAN(RETVAR,'零拾','零')
RETVAR = STRTRAN(RETVAR,'零角','零')
DO WHILE '零零'$RETVAR
RETVAR = STRTRAN(RETVAR,'零零','零')
ENDDO
RETVAR = STRTRAN(RETVAR,'零亿','亿')
RETVAR = STRTRAN(RETVAR,'零万','万')
RETVAR = STRTRAN(RETVAR,'亿万','亿零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零圆','圆零')
RETVAR = STRTRAN(RETVAR,'零零','零')
RETVAR = STRTRAN(RETVAR,'零分','整')
RETVAR = IIF(RETVAR=='','零圆整',RETVAR)
on error
RETURN FH+RETVAR
#5
我也有遇到这样的问题。。。