ABAP 人民币大小写转换程序

人民币大小写转换程序
程序来源群友,侵删

* 数字转换人民币大写的程序
* 定义数字对应的中文大写
data: begin of ch_num type string,
        "零" value '0',
        "壹" value '1',
        "贰" value '2',
        "叁" value '3',
        "肆" value '4',
        "伍" value '5',
        "陆" value '6',
        "柒" value '7',
        "捌" value '8',
        "玖" value '9',
      end of ch_num.

* 定义单位对应的中文大写
data: begin of ch_unit type string,
        "拾" value '1',
        "佰" value '2',
        "仟" value '3',
        "万" value '4',
        "亿" value '8',
        "元" value '0',
        "角" value '1',
        "分" value '2',
      end of ch_unit.

* 定义输入和输出变量
data: input type string,
      output type string.

* 获取用户输入
input = '123456.78'.

* 处理小数点后面的部分
if indexof( input, '.' ) > 0.
  * 获取小数部分
  data: dec_input type string,
        dec_output type string.
  dec_input = split_string( input, '.', 2 ).
  * 将小数部分转换成大写
  do 2 times.
    data: digit type string.
    digit = dec_input+offset( 1 ).
    dec_output = dec_output && ch_num+digit && ch_unit+offset( 1 ).
    dec_input = shift_left( dec_input, 1 ).
  enddo.
  * 删除转换完成的小数部分
  input = split_string( input, '.', 1 ).
endif.

* 将整数部分转换成大写
do 4 times.
  data: digit type string.
  digit = input+offset( 4 ).
  output = output && ch_num+digit && ch_unit+offset( 4 ).
  input = shift_left( input, 1 ).
enddo.

* 将转换完成的小数部分拼接到整数部分后面
output = output && dec_output.

* 输出转换完成的人民币大写
write output.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值