众所周知,SAP的数据基本都是四舍五入的
但是,有些时候就是需要不要四舍五入,直接截断,怎么办?
这么办:
REPORT Z_BARRY_TEST_ROUND .
DATA: pp1 TYPE p DECIMALS 3,
pp2 TYPE p DECIMALS 2,
pp3 TYPE p DECIMALS 2,
ii1 TYPE i .
pp1 = '1452.345'.
pp3 = pp1 .
ii1 = 2.
PERFORM noround USING pp1 ii1
CHANGING pp2.
WRITE: pp2,pp3.
*&--------------------------------------------------------------------*
*& Form noround
*&--------------------------------------------------------------------*
FORM noround USING p1 i1
CHANGING p2.
DATA: tmpn1(20) TYPE n ,
tmpn2(20) TYPE n ,
tmpc1(20) TYPE c .
tmpc1 = p1.
SPLIT tmpc1 AT '.' INTO tmpn1 tmpn2.
CONCATENATE tmpn1 '.' tmpn2+0(i1) INTO tmpc1.
p2 = tmpc1.
ENDFORM. "noround
或者:
REPORT z_barry_test.
DATA: p1 TYPE p DECIMALS 4.
p1 = '3.456'.
CALL FUNCTION 'ROUND'
EXPORTING
decimals = 2
input = p1
sign = '-'
IMPORTING
output = p1
EXCEPTIONS
input_invalid = 1
overflow = 2
type_invalid = 3
OTHERS = 4.
WRITE p1.
Sign:
SPACE |
: no rounding (input = output) |
'+' |
: round up |
'-' |
: round down |
'X' |
: commercial rounding |
阅读(8575) | 评论(3) | 转发(0) |