原贴地址:http://jiahongguang12.blog.163.com/blog/static/334665720071060551591/
输入参数12.5445,因此FM从小数点最后一位进位,FM参数 CONV_DEC =2 为精确到第2位小数 ,
打印结果:12.55;
REPORT Z_TEST_007.
DATA : DAT TYPE P DECIMALS 9 VALUE ‘12.5445’ ,
DAT1 TYPE P DECIMALS 9 .
* MOVE DAT TO DAT1.
CALL FUNCTION ‘HR_NZ_ROUNDING_DECIMALS’
EXPORTING
VALUE_IN = DAT ” Input field with decimals
CONV_DEC = 2 ” i Number of desired decimals for conversion
IMPORTING
VALUE_OUT = DAT1. ” Output field with rounded decimals
* EXCEPTIONS
* NO_ROUNDING_REQUIRED = 1 ” No rounding required. (CONV_DEC > VALUE_IN dec)
* DECIMALS_GREATER_THAN_10 = 2 ” Conversion only possible with decimals <= 10
* ROUNDING_ERROR = 3 ” An error occurred during the decimal conversion
* OTHERS = 4.
" HR_NZ_ROUNDING_DECIMALS
WRITE DAT1.
注:处理的数据必须是数值类型,SAP默认四舍五入,如果是P类型可以直接定义小数位来限制
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18302.html