Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Rounding off the Decimal value

Former Member
0 Likes
4,506

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

7 REPLIES 7
Read only

Former Member
0 Likes
2,815

Hi Nikihil,

check in the below link.,

http://scn.sap.com/thread/970561

Read only

hiriyappa_myageri
Participant
0 Likes
2,815

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

Read only

Former Member
0 Likes
2,815

Try FM 'J_1I6_ROUND_TO_NEAREST_AMT'

Read only

former_member220538
Active Participant
0 Likes
2,815

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

Read only

PeterJonker
Active Contributor
0 Likes
2,815

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.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,815

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

Read only

Former Member
0 Likes
2,815

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