shuxx

导航

将小写金额转换成大写金额

Function Money(thenumber)
  Dim tempMoney, i, String1, String2, length, checkp '定义变量
  Dim one()
  Dim onestr() '定义数组

  String1 = "零壹贰叁肆伍陆柒捌玖"
  String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分厘毫"

  checkp = InStr(thenumber, ".") '判断是否含有小数位
  If checkp <> 0 Then
    thenumber = Replace(thenumber, ".", "") '去除小数位
  End If

  length = Len(thenumber) '取得数据长度
  ReDim one(length - 1) '重新定义数组大小
  ReDim onestr(length - 1) '重新定义数组大小

  For i = 0 To length - 1

   one(i) = Mid(thenumber, i + 1, 1) '循环取得每一位的数字
   one(i) = Mid(String1, one(i) + 1, 1) '循环取得数字对应的大写

   If checkp = 0 Then
     '不含有小数的数据其数字对应的单位
     onestr(i) = Mid(String2, 14 - length + i, 1)
   Else
     '含有小数的数据其数字对应的单位
     onestr(i) = Mid(String2, 15 - length + i + Len(thenumber) - checkp, 1)
   End If

   one(i) = one(i) & onestr(i) '将数字与单位组合
  Next

  tempMoney = Replace(Join(one), " ", "") '取得数组中所有的元素,并连接起来
  tempMoney = Replace(tempMoney, "零元", "元")
  tempMoney = Replace(tempMoney, "零万", "万")
  tempMoney = Replace(tempMoney, "零亿", "亿")
  tempMoney = Replace(tempMoney, "零仟", "零")
  tempMoney = Replace(tempMoney, "零佰", "零")
  tempMoney = Replace(tempMoney, "零拾", "零")

  Do While Not InStr(tempMoney, "零零") = 0
    tempMoney = Replace(tempMoney, "零零", "零")
  Loop
  Money = tempMoney
End Function

msgbox Money("222.44")

posted on 2007-09-04 16:43  舒秀宣  阅读(273)  评论(0编辑  收藏  举报