‎2006 Dec 06 6:34 PM
Hello,
I am trying to write a function that does the following 2 things:
If a number is an integer, first add .00 after the integer, then add zeros in front such that altoghther it makes 9 characters (e.g.: 12 -> 000012.00)
If a number is not an integer, then ensure it is 2 decimals by truncating whatever that is after the 2 decimals and add 0 in fron as well (e.g. 12.12345 -> 000012.12)
There would be no number larger than 6 digits (i.e., 9 characters altogether)
Does anyone know whether there is any existing function or method that would do the job or at least part of it?
Thanks!
Regards,
Anyi
‎2006 Dec 06 7:05 PM
Hi Anyi,
Please try this.
DATA: NUM TYPE P05_DEC15_4,
ROUND TYPE MAXBT,
RESULT(10) TYPE C.
MOVE '12.12345' TO NUM.
CALL FUNCTION 'HR_NL_ROUNDING'
EXPORTING
INPUT = NUM
METHOD = '1'
IMPORTING
OUTPUT = ROUND.
MOVE ROUND TO RESULT.
SHIFT RESULT RIGHT.
TRANSLATE RESULT USING ' 0'.
WRITE: / RESULT.Regards,
Ferry Lianto
‎2006 Dec 06 6:39 PM
‎2006 Dec 06 6:45 PM
Hello,
So now the rounding and 2 decimal bit is resolved, anyone has any suggestion regarding the adding zero part?
Thanks Ferry for the suggestion!
Regards,
Anyi
> Hi,
>
> Please check FM HR_NL_ROUNDING.
>
> Regards,
> Ferry Lianto
‎2006 Dec 06 6:49 PM
use Function module "ROUND"
Raja T
Message was edited by:
Raja T
‎2006 Dec 06 6:59 PM
Err...I am more concerned with the 0s in front now...
Thanks anyways!
Anyi
> use Function module "ROUND"
>
> Raja T
>
> Message was edited by:
> Raja T
‎2006 Dec 06 6:52 PM
Hi Anyi,
This FM will do rounding into 2 decimals then you need to fill zeros.
Regards,
Ferry Lianto
‎2006 Dec 06 7:05 PM
Hi Anyi,
Please try this.
DATA: NUM TYPE P05_DEC15_4,
ROUND TYPE MAXBT,
RESULT(10) TYPE C.
MOVE '12.12345' TO NUM.
CALL FUNCTION 'HR_NL_ROUNDING'
EXPORTING
INPUT = NUM
METHOD = '1'
IMPORTING
OUTPUT = ROUND.
MOVE ROUND TO RESULT.
SHIFT RESULT RIGHT.
TRANSLATE RESULT USING ' 0'.
WRITE: / RESULT.Regards,
Ferry Lianto