First thing to note: native data is string in Jbase. So if you start with multiplying your data by 1, it will be converted to a number, including inner properties like zero suffixes will disappear.
- Rounding an amount according to pre-set formats:
FMT(number, format)
Example: Y.VAR = "8" : VM : "12" FMTS(Y.VAR,"R2") => gives Y.VAR = '8.00':VM:'12.00'
- Rounding an amount according to currency definition:
CALL EB.ROUND.AMOUNT(CCY,CURRENCY.AMT,param,””)
=> param: ‘1’ = non-cash rounding ‘2’ = cash rounding
- or alternatively you can code your own rounding routine:
CALL ROUNDING.TOOL(NUMBER.TO.ROUND,PARAMETER)
- Example of rounding routine that can be called in Enquiries, standard selections, etc…:
LIST F.SPF EVAL ‘SUBR(“ROUNDING.TOOL”,”-123.123456789″,”8″)’ AS MY.RESULT FMT 20L
@ID… MY.RESULT
SYSTEM -123.12345679
SUBROUTINE ROUNDING.TOOL(RESULT,YNUM.SIGNED,Y.ROUND.POS) $INSERT I_COMMON $INSERT I_EQUATE * by default return same value RESULT = NUMBER.TO.ROUND IF UNASSIGNED(NUMBER.TO.ROUND) THEN RETURN IF (NUMBER.TO.ROUND = '') THEN RETURN * default number of decimals to 6 IF UNASSIGNED(Y.ROUND.POS) THEN Y.ROUND.POS = 6 IF (Y.ROUND.POS = '') THEN Y.ROUND.POS = 6 * round number but do not maintains format IF (NUM(NUMBER.TO.ROUND) AND NUM(Y.ROUND.POS) AND (Y.ROUND.POS GE 0) AND (Y.ROUND.POS LE 9)) THEN RESULT = FMT(NUMBER.TO.ROUND,"R":Y.ROUND.POS) IF (NUM(RESULT)) THEN ; * NUM accept "+-." as numeric RESULT = TRIM(RESULT) ; * remove space IF (RESULT NE '+') THEN IF (RESULT NE '-') THEN IF (RESULT NE '.') THEN RESULT = RESULT * 1 END END END END END RETURN