·天新网首页·加入收藏·设为首页
首页|笔记本|手机|数码相机|摄像机|MP3/MP4|主板|内存|显示器|办公|打印机|下载|开发|汽车|学院|业界
硬件|台式机|数码|数字家庭|投影仪|GPS/CPU|显卡|硬盘|服务器|网络|一体机|驱动|源码|游戏|考试|报价
将人民币金额转换成大写的金额
http://dev.21tx.com 2005年03月13日

提供两种方法:

//////////////////////////////////////////////////////////////////////
//将钱数转化为大写
//////////////////////////////////////////////////////////////////////
constant string ls_bit = "万仟佰拾亿仟佰拾万仟佰拾元角分"
constant string ls_num = "壹贰叁肆伍陆柒捌玖"
long lmax = len( ls_bit ) + 1
string ls_je, ls_dw, ls_result = ''
long ll_len, i, k
ls_je = string( data, "#############.00" )
ll_len = len( ls_je ) - 1
ls_je = replace( ls_je, ll_len - 1, 1, '' )
for i = ll_len to 1 step -1
lmax -= 2
ls_dw = mid( ls_bit, lmax, 2 )
k = long( mid( ls_je, i, 1 ) )
if k = 0 then
choose case ls_dw
case '元','万','亿'
ls_result = ls_dw + ls_result
case '分'
ls_result = '整'
case '角'
if ls_result <> '整' then ls_result = '零' + ls_result
case else
choose case left( ls_result, 2 )
case '万', '亿', '元', '零'
case else
ls_result = '零' + ls_result
end choose
end choose
else
ls_result = mid( ls_num, k * 2 - 1, 2 ) + ls_dw + ls_result
end if
next
return ls_result


--------------------------------------------------------
//入口参数:DECIMAL numb
INTEGER i //循环变量
STRING s_numb //以字符串表示
STRING s_money
INTEGER i1
s_numb = String(numb,"########.00")
IF Len(s_numb) < 11 THEN s_numb = Space(11-len(s_numb))+s_numb
i = 1
s_money = ""
//去掉前导空格
DO WHILE i<8 AND Mid(s_numb,i,1) = " "
i ++
LOOP

i1 = 11 - i + 1

INTEGER digit
DO WHILE i<=4
digit = Integer(Mid(s_numb,i,1))
IF digit = 0 THEN
DO WHILE i<=4
digit = Integer(Mid(s_numb,i,1))
IF digit <>0 THEN exit
i ++
LOOP
IF i<=4 THEN s_money += "零"
ELSE
s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) +&
Mid("仟佰拾万",i*2-1,2)
i ++
END IF
LOOP

IF i1 >= 8 THEN
IF Integer(Mid(s_numb,4,1)) = 0 THEN s_money += "万"
END IF

DO WHILE i<=8
digit = Integer(Mid(s_numb,i,1))
IF digit = 0 THEN
DO WHILE i<=8
digit = Integer(Mid(s_numb,i,1))
IF digit<>0 THEN exit
i ++
LOOP
IF i<=8 THEN
s_money += "零"
ELSE
IF Integer(Mid(s_numb,1,8)) <> 0 THEN
s_money += "元"
IF Integer(Mid(s_numb,11,1))<>0 THEN s_money += "零"
END IF
END IF
END IF
IF digit <> 0 THEN
s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) + &
Mid("仟佰拾万仟佰拾元",i*2-1,2)
END IF
i ++
LOOP

digit = Integer(Mid(s_numb,10,1))
IF digit<>0 THEN
s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) + "角"
ELSE
IF Integer(Mid(s_numb,11,1))<>0 AND Integer(Mid(s_numb,1,9)) <> 0 THEN
s_money += "零"
END IF
END IF

digit = Integer(Mid(s_numb,11,1))
IF digit <> 0 THEN
s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) + "分"
ELSE
IF Len(Trim(s_money)) <> 0 THEN s_money += "整"
END IF

RETURN s_money

上一篇: Powerbuilder中怎样实现用代码配置ODBC
下一篇: 使用PowerDesigner 9.5创建Web服务

Google
 
热点文章
关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图
Copyright © 2000-2008 , www.21tx.com , All Rights Reserved .
© 晨新科技 版权所有 Created by TXSite.net