• PowerBuilder -- 数字金额大写


    //====================================================================
    // 事件: .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
  • 相关阅读:
    Spring中的事务传播行为与隔离级别
    redis分布式共享锁模拟抢单的实现
    synchronized关键字修饰非静态方法与静态方法的区别
    docker安装Tensorflow并使用jupyter notebook
    python 图像处理(4):图像的绘制
    python 图像处理(3):图像数据类型及颜色空间转换
    python 图像处理 (2):图像像素的访问与裁剪
    python 读取图像的几种方法
    python 图像处理:图像的读取、显示与保存
    NLP 正向、逆向 分词
  • 原文地址:https://www.cnblogs.com/yarightok/p/7264450.html
Copyright © 2020-2023  润新知