金额大写

Function  RMB(money)

money 
=   FormatNumber (money,  2 ' 精确到小数点两位(实现角分)

Dim  moneyBigList  ' 零壹贰叁肆伍陆柒捌玖
Dim  unitList    ' 分角元拾佰仟万拾佰仟亿拾佰仟万

Dim  moneystr   ' 数字金额字符串(money * 100)
Dim  moneyLen   ' 数字金额字符串长度(money * 100)

Dim  moneyChar  ' 小写金额:单个位数
Dim  n1, n2     ' "零壹贰叁肆伍陆柒捌玖":单个字符,"分角元拾佰仟万拾佰仟亿拾佰仟万":单个字符

Dim  n          ' 循环变量
Dim  moneyBig  ' 大写金额

moneyBigList 
=   " 零壹贰叁肆伍陆柒捌玖 "
unitList 
=   " 分角元拾佰仟万拾佰仟亿拾佰仟万 "

If  money  >   9999999999999.99   Then   ' 限制最大值(99999亿9999万9999元9角9分)
    rmb  =   " 超出范围的人民币值 "
    
Exit   Function
End   If

moneystr 
=   CStr (money  *   100 ' 转换成分
moneyLen  =   Len (moneystr)      ' 获得长度

=   1
Do   While  n  <=  moneyLen
    moneyChar 
=   CInt ( Mid (moneystr, n,  1 ))      ' 小写金额:单个位数
    n1  =   Mid (moneyBigList, moneyChar  +   1 1 )   ' 大写金额:单个字符
    n2  =   Mid (unitList, moneyLen  -  n  +   1 1 )     ' 单位
     If   Not  n1  =   " "   Then
        moneyBig 
=  moneyBig  +   CStr (n1)  +   CStr (n2)
    
Else
        
If  n2  =   " 亿 "   Or  n2  =   " "   Or  n2  =   " "   Or  n1  =   " "   Then
            
Do   While   Right (moneyBig,  1 =   " "
            moneyBig 
=   Left (moneyBig,  Len (moneyBig)  -   1 )
            
Loop
        
End   If
        
If  (n2  =   " 亿 "   Or  (n2  =   " "   And   Right (moneyBig,  1 <>   " 亿 " Or  n2  =   " " Then
            moneyBig 
=  moneyBig  +   CStr (n2)
        
Else
            
If   Left ( Right (moneyBig,  2 ),  1 =   " "   Or   Right (moneyBig,  1 <>   " 亿 "   Then
                moneyBig 
=  moneyBig  +  n1
            
End   If
        
End   If
    
End   If
    
    n 
=  n  +   1
Loop

Do   While   Right (moneyBig,  1 =   " "   ' 去掉最右边的"零"
    moneyBig  =   Left (moneyBig,  Len (moneyBig)  -   1 )
Loop

If   Right (moneyBig,  1 =   " "   Then   ' 加上"整"
    moneyBig  =  moneyBig  +   " "
End   If

RMB 
=  moneyBig  ' 返回大写金额
End Function

 

 '调用方法
Response.Write(RMB(1986))

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值