cancel
Showing results for 
Search instead for 
Did you mean: 

round a decimal to nearest integer

Former Member
0 Kudos

hello

does anybody know how to round a value to the nearest integer in a smartform

if the value is 2.67, it should be 3

if the value is 3.01, it should be 3

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hope this will help you

DATA : l_var(4) TYPE p decimals 3.

DATA : l_var2(4) TYPE p decimals 2.

l_var = '4.017'.

CALL FUNCTION 'ROUND'

EXPORTING

DECIMALS = 3

input = l_var

IMPORTING

OUTPUT = l_var2.

write : l_var2.

plz reward if useful

vivek

Former Member
0 Kudos

I tried to execute the fm by inputting decimals 2, input 3.88, im getting nothing!

can u help me

venkat_o
Active Contributor
0 Kudos

Anjali Check this sample program. It works fine.

REPORT zvenkat_test2.

DATA: l_value1 TYPE p0008-anz02 VALUE '2.67',
      l_value2 TYPE p0008-anz02 VALUE '3.10',
      l_value3 TYPE i,
      l_value4 TYPE i.

CALL FUNCTION 'ROUND'
  EXPORTING
    decimals            = 2
    input               = l_value1
   sign                = '+'
 IMPORTING
   output              = l_value3
* 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 / l_value3.
CALL FUNCTION 'ROUND'
  EXPORTING
    decimals            = 2
    input               = l_value2
   sign                = '+'
 IMPORTING
   output              = l_value4
* 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 / l_value4.
Regards, Venkat.O

Former Member
0 Kudos

hi thanks for the reply

cn we just write the following statement:

WRITE zsum TO zsum_char ROUND 2.

zsum is of type F, and zsum_char is of type character

Former Member
0 Kudos

Hi

Use this FM

call function 'HR_IN_ROUND_AMT'

exporting

amount = Give the amount to be round off

rndoff = 100 " This is for round off to two decimal point

rndlmt = 'N' " Nearest Value

importing

retamt = Round off amount

dltamt = Gives Difference

Regards

Rajesh

Answers (1)

Answers (1)

Former Member
0 Kudos

hi,

use &ITAB-LFKIMG(C)& to write the integer part.

reward points if useful.

regards,

sandhya.