2013 Sep 20 12:43 PM
Hello Experts,
Is there and Keyword or Function module for rounding off the Decimal value .
For Example :
1.1 should be rounded of to 2
99.9 should be rounded of to 100 .
95.4 should be rounded of to 96
95.6 should be rounded of to 96.
Please suggest on this .
Thanks and Regards,
Nikhil Kulkarni
Hello Experts,
Is there and Keyword or Function module for rounding off the Decimal value .
For Example :
1.1 should be rounded of to 2
99.9 should be rounded of to 100 .
95.4 should be rounded of to 96
95.6 should be rounded of to 96.
Please suggest on this .
Thanks and Regards,
Nikhil Kulkarni
2013 Sep 20 12:49 PM
2013 Sep 20 12:52 PM
Hi Nikhil,
Try These,
The function CEIL or FLOOR might help.
The ABS, SIGN, CEIL, FLOOR, TRUNC, and FRAC Functions
DATA: I TYPE I,
P TYPE P DECIMALS 2,
M TYPE F VALUE '-3.5',
D TYPE P DECIMALS 1.
P = ABS( M ). " 3,5
I = P. " 4 - business rounding
I = M. " -4
I = CEIL( P ). " 4 - next largest whole number
I = CEIL( M ). " -3
I = FLOOR( P ). " 3 - next smallest whole number
I = FLOOR( M ). " -4
I = TRUNC( P ). " 3 - integer part
I = TRUNC( M ). " -3
D = FRAC( P ). " 0.5 - decimal part
D = FRAC( M ). " -0.5
Regards,
Hiriyappa
2013 Sep 20 12:55 PM
2013 Sep 20 12:57 PM
Hi,
Use the code below
DATA : v_no TYPE p DECIMALS 2 VALUE '2.6',
v_num2 TYPE char10,
v_num1 TYPE char10 ,
v_char TYPE char10.
v_char = v_no.
SPLIT v_char AT '.' INTO v_num1 v_num2.
IF v_num2 > 0.
v_num1 = v_num1 + 1.
ENDIF.
WRITE v_num1.
Regards,
Jeffin
2013 Sep 20 12:59 PM
I don't know of any function module, but the following code will do this for you:
p_test2 is the field with decimals.
DATA: lv_help TYPE i.
lv_help = p_test2. " decimals truncated
IF lv_help = p_test2.
* only zeroes as decimals, no need to round
ELSE.
lv_help = lv_help + 1.
ENDIF.
2013 Sep 20 1:02 PM
Look first at online Abap documentation (like F1 on editor or ABAPDOCU navigation) for "round"
(e.g. : round, rescale - Rounding Functions or documentation of a class like CL_ABAP_MATH.)
If you actually require a FM look with SE37 at the FM containing ROUND in their name (and not containing BACK...) starting with FM ROUND...
Regards,
Raymond
2013 Sep 20 1:07 PM
Hi Use below F.M
Try using FM ROUND
with
decimals = 1
sign = 'X' (Commercial rounding)
and
CO_R0_FLOAT_ROUND_RESULT
Or
Code:
DATA :
wa_test(10) TYPE p DECIMALS 2.
wa_test = '15.67'.
wa_test = CEIL( wa_test ).
DATA :
wa_test1(10) TYPE p DECIMALS 2.
wa_test1 = '15.67'.
wa_test1 = FLOOR( wa_test1 ).
WRITE: wa_test , wa_test1.
Regards,
Giri
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |