java如何给数字每三位加一个逗号_在数字字符串中按每三位添加一个逗号 | 学步园...

perform format_numeric using gt_sf_head-debit gt_sf_head-debit.

form format_numeric using num_org num_tag.

data : lt_num type table of string with header line.

data : l_num(100) type c.

data : l_dec type string.

data : l_len type i.

data : l_temp_str01 type string.

data : l_temp_str02(1) type c.

data : l_temp_str03 type string.

move num_org to num_tag.

* 在字符串里加逗号

split num_tag at ‘.’ into table lt_num in character mode.

* 获取整数部分和小数部分

loop at lt_num.

l_temp_str01 = lt_num.

at first.

l_num = l_temp_str01.

endat.

at last.

l_dec = l_temp_str01.

endat.

endloop.

l_len = strlen( l_num ).

do l_len times.

l_len = l_len - 1.

l_temp_str02 = l_num+l_len(1).

concatenate l_temp_str03 l_temp_str02 into l_temp_str03.

enddo.

l_num = l_temp_str03.

clear : lt_num.

refresh : lt_num.

call function ‘RKD_WORD_WRAP’

exporting

textline = l_num

delimiter = ‘ ‘

outputlen = 3

* IMPORTING

* OUT_LINE1 =

* OUT_LINE2 =

* OUT_LINE3 =

tables

out_lines = lt_num

exceptions

outputlen_too_large = 1

others = 2.

if sy-subrc 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

clear : l_num.

loop at lt_num.

concatenate l_num ‘,’ lt_num into l_num.

endloop.

shift l_num by 1 places.

l_len = strlen( l_num ).

clear : l_temp_str03.

do l_len times.

l_len = l_len - 1.

l_temp_str02 = l_num+l_len(1).

concatenate l_temp_str03 l_temp_str02 into l_temp_str03.

enddo.

l_num = l_temp_str03.

* 重新赋值

clear : num_tag.

concatenate l_num ‘.’ l_dec into num_tag.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值