码迷,mamicode.com
首页 > 其他好文 > 详细

PowerBuilder -- 数字金额大写

时间:2017-07-31 18:54:48      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:als   hang   大写   build   --   ade   数字转换   小数   unit   

//====================================================================
// 事件: .pub_fc_change_number()
//--------------------------------------------------------------------
// 描述: 数字转换成大写
//--------------------------------------------------------------------
// 参数:
//     decimal    number    
//--------------------------------------------------------------------
// 返回:  string//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================
String cn_num[10] = {"","","","","","","","","",""} //大写0-9
String cn_carry[19] = {"","","","","","","","","","","","亿","","","","","","",""} //单位
String ls_pos,ls_old,ls_number,ls_rc = ‘‘, ls_zero, ls_zero_unit
Integer li_i,li_len //循环变量
String ls_zf = ‘‘ //正负符号
String ls_value, ls_z
Boolean lb_zero_yuan
//参数格式化
If ade_number < 0 Then
    ls_zf = 
    ade_number = (-1)*ade_number
End If
ls_number = String(ade_number,"0.00")
//参数的长度
li_len = Len(ls_number)
ls_zero = ‘‘
ls_zero_unit = ‘‘
lb_zero_yuan = False
ls_z = ‘‘
//转换为大写(发票格式),从右到左
For li_i = 1 To li_len
    ls_value = Mid(ls_number, li_len - li_i + 1, 1)
    If li_i = 1 And ls_value = 0 Then
        // 分 为0
        ls_z = 
        Continue
    End If
    If li_i = 2 And ls_value = 0 And ls_z <>  Then
        // 角 为0, 分不为 0
        ls_rc =  + ls_rc
        Continue
    End If
    
    // 小数点
    If li_i = 3 Then Continue
    
    // 万与元,亿与万之间 存在 0
    If (li_i = 8 Or li_i = 12) And ls_zero =  Then
        ls_rc =  + ls_rc
        ls_zero = ‘‘
    End If
    
    // 元 万 亿 为0
    If li_len > 4 And (li_i = 4 Or li_i = 8 Or li_i = 12) And ls_value = 0 Then
        ls_rc = cn_carry[li_i] + ls_rc
        lb_zero_yuan = True
        Continue
    End If
    // 万与元,亿与万之间 存在 0
    If li_len > 5 And li_i > 4 And ls_value = 0 And ls_zero = ‘‘ And Not lb_zero_yuan Then
        ls_zero = 
    End If
    
    If ls_value <> 0 Or li_i = 4 Then
        ls_rc = cn_num[1 + Mod(Integer(ls_value), 10)] + cn_carry[li_i] + ls_zero + ls_rc
        ls_zero = ‘‘
        lb_zero_yuan = False
    End If
    
Next

ls_rc = ls_zf + ls_rc + ls_z

Return ls_rc //返回结果  100100.11 100100100.11 10010100100.11

 

PowerBuilder -- 数字金额大写

标签:als   hang   大写   build   --   ade   数字转换   小数   unit   

原文地址:http://www.cnblogs.com/yarightok/p/7264450.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!