Application Development 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: 

To Round the Number

Former Member
0 Kudos

HI All,

Suppose a number is like this 3.25

I need to round the number to 4.

Pls tell me how to make it.

Thanks and regards,

shake sha vali

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

Either use function module " Round ".

data input type p decimals 2 value '12.11'.
data output type p decimals 2.

CALL FUNCTION 'ROUND'
  EXPORTING
   DECIMALS            = 2
    input               = input
   SIGN                = '+'
 IMPORTING
   OUTPUT              = output
* EXCEPTIONS
*   INPUT_INVALID       = 1
*   OVERFLOW            = 2
*   TYPE_INVALID        = 3
*   OTHERS              = 4
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write: output.

Or

use CIEL(3.25).

i.e.

data: n1 TYPE p decimals 2 value '3.25',
      n2 type i.
   n2 = CEIL( n1 ).
    write: n2.
  
n2 = 4.

thanx.

5 REPLIES 5

Former Member
0 Kudos

hi,

Either use function module " Round ".or

use CIEL(3.25).

Former Member
0 Kudos

hii

use like below code


DATA val1 TYPE P DECIMALS 2.
DATA val3 TYPE P DECIMALS 2.
DATA val2 TYPE P DECIMALS 2 VALUE '3.24'.
DATA val type p decimals 2 value '0.5'.

val3 = FRAC( val2 ).
if  val3 > val  .
val1 = floor( val2 ).
else.
val1 = ceil( val2 ).
endif.

write:/ val1.
write:/ val2.

regards

twinkal

Former Member
0 Kudos

It is coming after calculation or it is a static value

Regards,

Rajneesh Gupta

Former Member
0 Kudos

hi,

Either use function module " Round ".

data input type p decimals 2 value '12.11'.
data output type p decimals 2.

CALL FUNCTION 'ROUND'
  EXPORTING
   DECIMALS            = 2
    input               = input
   SIGN                = '+'
 IMPORTING
   OUTPUT              = output
* EXCEPTIONS
*   INPUT_INVALID       = 1
*   OVERFLOW            = 2
*   TYPE_INVALID        = 3
*   OTHERS              = 4
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write: output.

Or

use CIEL(3.25).

i.e.

data: n1 TYPE p decimals 2 value '3.25',
      n2 type i.
   n2 = CEIL( n1 ).
    write: n2.
  
n2 = 4.

thanx.

Former Member
0 Kudos

DATA a type p DECIMALS 2 VALUE '3.25'.

a = CEIL( a ).

WRITE a.