# 自己写的截取小数位的函数

CALL FUNCTION 'ZFN_GET_ROUND'
EXPORTING
PI_VALUE =　"要处理的数据
PI_LEN =　"要載取的小數點後面的位數
PI_TYPE = 'A' "載取方法：A 四舍五入 B 舍去後面的數，不處理進位問題 C 後面一位衹要大於0都要進位
IMPORTING
PO_VALUE = .　"返回的最后结果

FUNCTION ZFN_PB_W_0114.
*"----------------------------------------------------------------------
*"*"區域介面：
*" IMPORTING
*" REFERENCE(PI_VALUE)
*" REFERENCE(PI_LEN) TYPE I
*" REFERENCE(PI_TYPE) TYPE CHAR1 DEFAULT 'A'
*" EXPORTING
*" REFERENCE(PO_VALUE)
*"----------------------------------------------------------------------

DATA: TMP_VALUE TYPE STRING,
TMP_INT TYPE STRING,
TMP_SCALE TYPE STRING.
DATA: TMP_LAST TYPE C LENGTH 1,
TMP_VAL TYPE I,
TMP_LVAL TYPE I.

* BREAK-POINT 'GC_JIMHUANG'.
* IF PI_VALUE = 0. PO_VALUE = 0 . EXIT. ENDIF.
TMP_VALUE = PI_VALUE.
CONDENSE TMP_VALUE.
SPLIT TMP_VALUE AT '.' INTO: TMP_INT TMP_SCALE.
CONDENSE: TMP_INT,TMP_SCALE.

IF TMP_SCALE = ''. PO_VALUE = PI_VALUE. EXIT. ENDIF.

CASE PI_TYPE.
WHEN 'A'. " 四舍五入
TMP_VAL = TMP_SCALE+0(PI_LEN).
TMP_LAST = TMP_SCALE+PI_LEN(1).
IF TMP_LAST = ''. TMP_LAST = '0'. ENDIF.
TMP_LVAL = TMP_LAST.
IF TMP_LVAL >= 5.
TMP_VAL = TMP_VAL + 1.
ENDIF.
TMP_SCALE = TMP_VAL.
CONDENSE TMP_SCALE.

IF STRLEN( TMP_SCALE ) > PI_LEN.
TMP_SCALE = TMP_SCALE+1(PI_LEN).
TMP_VAL = TMP_INT.
TMP_VAL = TMP_VAL + 1.
TMP_INT = TMP_VAL.
CONDENSE TMP_INT.
ENDIF.

DO PI_LEN TIMES.
IF STRLEN( TMP_SCALE ) < PI_LEN.
CONCATENATE '0' TMP_SCALE INTO TMP_SCALE.
ELSE.
EXIT.
ENDIF.
ENDDO.

CONCATENATE TMP_INT '.' TMP_SCALE INTO TMP_VALUE .
CONDENSE TMP_VALUE.

PO_VALUE = TMP_VALUE.

WHEN 'B'. "舍去後面的數，不處理進位問題
TMP_SCALE = TMP_SCALE+0(PI_LEN).
CONDENSE TMP_SCALE.
CONCATENATE TMP_INT '.' TMP_SCALE INTO TMP_VALUE .
CONDENSE TMP_VALUE.

PO_VALUE = TMP_VALUE.

WHEN 'C'. "後面一位衹要大於0都要進位
* BREAK-POINT 'GC_JIMHUANG'.
TMP_VAL = TMP_SCALE+0(PI_LEN).
TMP_LAST = TMP_SCALE+PI_LEN(1).
IF TMP_LAST <> '0' AND TMP_LAST <> ''.
TMP_VAL = TMP_VAL + 1.
ENDIF.
TMP_SCALE = TMP_VAL.
CONDENSE TMP_SCALE.

IF STRLEN( TMP_SCALE ) > PI_LEN.
TMP_SCALE = TMP_SCALE+1(PI_LEN).
TMP_VAL = TMP_INT.
TMP_VAL = TMP_VAL + 1.
TMP_INT = TMP_VAL.
CONDENSE TMP_INT.
ENDIF.

DO PI_LEN TIMES.
IF STRLEN( TMP_SCALE ) < PI_LEN.
CONCATENATE '0' TMP_SCALE INTO TMP_SCALE.
ELSE.
EXIT.
ENDIF.
ENDDO.

CONCATENATE TMP_INT '.' TMP_SCALE INTO TMP_VALUE .
CONDENSE TMP_VALUE.

PO_VALUE = TMP_VALUE.
IF PO_VALUE = '' OR PO_VALUE IS INITIAL.
PO_VALUE = 0.
ENDIF.
ENDCASE.

ENDFUNCTION.

• 博文量
268
• 访问量
1431990