# 用VB把数字转成中文字符串

t=GetChinaNum(20005.000436, , , 7)'返回 “二千零五点零零零四三六”
t=GetChinaNum(2005.436, True, , 7)'返回“贰仟零伍元肆角肆分”
t=GetChinaNum(2005.436, , True, 7)'返加“二零零五点四三六”

Function  GetChinaNum(otherNum  As   Double , Optional isRMB  As   Boolean , Optional numOption  As   Boolean , Optional dotNum  As   Integer As   String

On   Error   Resume   Next
num
=   Trim (Str( Int (otherNum)))

If  isRMB  Then
numwei
=   " 拾佰仟万拾佰仟亿拾佰仟 "
numshu
=   " 零壹贰叁肆伍陆柒捌玖拾 "

Else
numwei
=   " 十百千万十百千亿十百千 "
numshu
=   " 零一二三四五六七八九十 "

End   If

If  otherNum  <   20   And  otherNum  >=   10   Then
num
=   Right (num,  1 )
GetChinaNum
=   Left (numwei,  1 )

End   If

For  i  =   1   To   Len (num)
bstr
=   Mid (num, i,  1 )

If  numOption  Then
GetChinaNum
=  GetChinaNum  +   Mid (numshu, Val(bstr)  +   1 1 )

Else
GetChinaNum
=  GetChinaNum  +   Mid (numshu, Val(bstr)  +   1 1 )

If  bstr  =   " 0 "   Then

If   Mid (numwei,  Len (num)  -  i,  1 =   " "   Or   Mid (numwei,  Len (num)  -  i,  1 =   " 亿 "   Then

Do   While   Right (GetChinaNum,  1 =   " "
GetChinaNum
=   Left (GetChinaNum,  Len (GetChinaNum)  -   1 )

Loop
GetChinaNum
=  GetChinaNum  +   Mid (numwei,  Len (num)  -  i,  1 )

End   If

Else

GetChinaNum
=  GetChinaNum  +   Mid (numwei,  Len (num)  -  i,  1 )

End   If
GetChinaNum
=   Replace (GetChinaNum,  " 零零 " " " )

End   If

Next  i

If  numOption  =   False   Then

Do   While   Right (GetChinaNum,  1 =   " "
GetChinaNum
=   Left (GetChinaNum,  Len (GetChinaNum)  -   1 )

Loop

End   If

If  isRMB  Then
numrmb
=   " 元角分 "
GetChinaNum
=  GetChinaNum  +   Mid (numrmb,  1 1 )

If  Val(num)  <>  otherNum  Then
num
=   Trim (Str( Round (otherNum  -  Val(num),  2 )))

For  i  =   2   To   Len (num)
bstr
=   Mid (num, i,  1 )
GetChinaNum
=  GetChinaNum  +   Mid (numshu, Val(bstr)  +   1 1 +   Mid (numrmb, i,  1 )

Next  i

Else
GetChinaNum
=  GetChinaNum  +   " "

End   If

Else

If  Val(num)  <>  otherNum  Then

If  dotNum  =   0   Then  dotNum  =   4
num
=   Trim ( CStr ( Round (otherNum  -  Val(num), dotNum)))

If  GetChinaNum  =   ""   Then  GetChinaNum  =   " "
GetChinaNum
=  GetChinaNum  +   " "

For  i  =   2   To   Len (num)
bstr
=   Mid (num, i,  1 )
GetChinaNum
=  GetChinaNum  +   Mid (numshu, Val(bstr)  +   1 1 )

Next  i

End   If

End   If
End Function

• 0
点赞
• 1
收藏
觉得还不错? 一键收藏
• 0
评论
03-16 4005
12-11 1320
10-20 789
11-15 9292
01-25 1068
05-07 3877
02-03
01-29
04-23
02-28

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

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

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