小写金额转换为大写

本人在网上看了其他朋友写的小写转大写代码,自己闲来无事也写了一个,测试了一下暂时没发现错漏,新人发帖,大家多提意见。

传入的唯一参数 decimal ld_dec

 

String dxint[13],dxdec[13],sz[13]
String dxstr = "仟佰拾一" //最後的一是便於取值,使單位的位數與數值相對應
String szstr = "零壹貳叁肆伍陸柒捌玖"

string ls_len ,ls_zhengshu,ls_xiaoshu

ls_len = string(ld_dec,'#.00')

// 整數部分
ls_zhengshu = mid(ls_len,1,pos(ls_len,'.')-1)
//小數部分
ls_xiaoshu = mid(ls_len,pos(ls_len,'.')+1,2)

int i,li_len,j
string ls_ii,ls_last,ls_yi,ls_wan,ls_yuan
li_len = len(ls_zhengshu) // 數字的長度

// 把數值分成三組,分別處理
if li_len > 8 then  // 上億
	ls_yi = mid(ls_zhengshu,1,li_len - 8)
	ls_wan = mid(ls_zhengshu,li_len - 7 ,4)
	ls_yuan = mid(ls_zhengshu,li_len - 3 ,4)

elseif li_len > 4 then // 上萬
	ls_yi = ''
	ls_wan = mid(ls_zhengshu,1,li_len - 4)
	ls_yuan = mid(ls_zhengshu,li_len - 3 ,4)
else
	ls_yi = ''
	ls_wan = ''
	ls_yuan = ls_zhengshu
	
end if
	
//判斷是否上億
if isnull(ls_yi) or ls_yi = '' then 

else
	j = len(ls_yi)
	for i=1 to len(ls_yi)
		ls_ii = mid(ls_zhengshu,i,1) // 獲取單個數字
		
/** 此段代碼可重複利用 -------------------**/
		sz[i] = mid(szstr,integer(ls_ii)*2+1,2) // 獲取數字對應的中文
		
		dxint[i] = mid(dxstr,len(dxstr) - j*2 + 1,2)// 獲取數字對應的單位
		
		// 把十位去掉
		if dxint[i] = '一' then	dxint[i] = ''
		
		// 把數值是零的單位去掉
		if sz[i] = '零' and (dxint[i]='拾' or dxint[i]='佰')  then dxint[i]='' 
		
		ls_last +=  sz[i] + dxint[i]
		
		// 去掉一個重複的零
		if mid(ls_last,len(ls_last)-3,4) = '零零' then	ls_last = mid(ls_last,1,len(ls_last)-2)
		j --
	next
	// 最後一位是零,去掉
	if mid(ls_last,len(ls_last)-1,2) = '零' then	ls_last = mid(ls_last,1,len(ls_last)-2)
	
/*---------------------------------------*/
	ls_last += '億'
	
end if

if isnull(ls_wan) or ls_wan = '' then 
	
else
	j = len(ls_wan)
	
	for i=1 to len(ls_wan)
		ls_ii = mid(ls_wan,i,1) // 獲取數字對應的中文
		sz[i] = mid(szstr,integer(ls_ii)*2+1,2) // 獲取數字對應的單位
		
		dxint[i] = mid(dxstr,len(dxstr) - j*2 + 1,2)
		
		// 把十位去掉
		if dxint[i] = '一' then	dxint[i] = ''
		
		// 把數值是零的單位去掉
		if sz[i] = '零' and (dxint[i]='拾' or dxint[i]='佰' or dxint[i]='仟')  then dxint[i]='' 
		
		ls_last +=  sz[i] + dxint[i]
		
		// 去掉一個重複的零
		if mid(ls_last,len(ls_last)-3,4) = '零零' then	ls_last = mid(ls_last,1,len(ls_last)-2)
		j --
	next
	// 最後一位是零,去掉
	if mid(ls_last,len(ls_last)-1,2) = '零' then	ls_last = mid(ls_last,1,len(ls_last)-2)
	
	ls_last += '萬'
end if
	
	// 去除億萬單位重複的情況
	if mid(ls_last,len(ls_last)-3,4) = '億萬' then	ls_last = mid(ls_last,1,len(ls_last)-2)
	
j = len(ls_yuan)
for i=1 to len(ls_yuan)
	ls_ii = mid(ls_yuan,i,1) // 獲取數字對應的中文
	sz[i] = mid(szstr,integer(ls_ii)*2+1,2) // 獲取數字對應的單位
		
		dxint[i] = mid(dxstr,len(dxstr) - j*2 + 1,2)
		
		// 把十位去掉
		if dxint[i] = '一' then	dxint[i] = ''
		
		// 把數值是零的單位去掉
		if sz[i] = '零' and (dxint[i]='拾' or dxint[i]='佰' or dxint[i]='仟')  then dxint[i]='' 
		
		ls_last +=  sz[i] + dxint[i]
		
		// 去掉一個重複的零
		if mid(ls_last,len(ls_last)-3,4) = '零零' then	ls_last = mid(ls_last,1,len(ls_last)-2)
		j --
	next
	// 最後一位是零,去掉
	if mid(ls_last,len(ls_last)-1,2) = '零' then	ls_last = mid(ls_last,1,len(ls_last)-2)

ls_last += '元'

// 小數部分
if ls_xiaoshu = '00' then
	ls_last += '整' 
else
	ls_ii = mid(ls_xiaoshu,1,1) // 獲取單個數字
	sz[i] = mid(szstr,integer(ls_ii)*2+1,2)// 獲取數字對應的中文
	ls_last += sz[i] + '角'
	
	ls_ii = mid(ls_xiaoshu,2,1) // 獲取單個數字
	sz[i] = mid(szstr,integer(ls_ii)*2+1,2) // 獲取數字對應的中文
	ls_last += sz[i] + '分'
	
end if

return ls_last

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值