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 value

Former Member
0 Likes
1,573

Hi,

Please tell me the syntax to round off the value.

eg: 95.5 to 96.

Thanks in advance,

Priya.

Hi,

Please tell me the syntax to round off the value.

eg: 95.5 to 96.

Thanks in advance,

Priya.

6 REPLIES 6
Read only

Former Member
0 Likes
1,478

use ceil or floor commands



data: v_amt type p decimals 1 value '95.5',

v_amt = ceil( v_amt ).
v_amt = v_amt + 1.

write:/ v_amt.


Read only

Former Member
0 Likes
1,478

use numeric type..it has the future to round off.....

Regards

Anbu

Read only

GauthamV
Active Contributor
0 Likes
1,478

hi,

use these arthimetic operations.

CEIL

Smallest integer value that is not less than x

FLOOR

Largest integer value that is not greater than x

TRUNC

Interger part of x

FRAC

Decimal part of x

Read only

Former Member
0 Likes
1,478

use like this:

CALL FUNCTION 'ROUND'
      EXPORTING
        DECIMALS      = 2
        INPUT         = temp_bvmtt
        SIGN          = 'X'
      IMPORTING
        OUTPUT        = loc_bvmtt
      EXCEPTIONS
        INPUT_INVALID = 1
        OVERFLOW      = 2
        TYPE_INVALID  = 3
        OTHERS        = 4.

Amit

Read only

Former Member
0 Likes
1,478

Declare a variable of TYPE I and move the value into it. It automatically rounds up the value.

Regards,

Kiran

Read only

Former Member
0 Likes
1,478

Hi,

Please refer the example below: (Extract from FM documentation)



DATA: VALUE TYPE F,
      ROUND_VALUE TYPE F.
...
CALL FUNCTION 'ROUND'
     EXPORTING
          DECIMALS = 2-
          INPUT    = VALUE
          SIGN     = '+'
     IMPORTING
          OUTPUT   = ROUND_VALUE
     EXCEPTIONS
          INPUT_INVALD = 01
          OVERFLOW     = 02
          TYPE_INVALID = 03. 

This function module rounds the value INPUT to ANDEC decimal places. The parameter SIGN determines whether rounding is down ('-'), up ('+') or commercial ('X').

If SIGN = SPACE, there is no rounding (OUTPUT = INPUT).

Note

The result of floating point rounding calculations can be incorrect in certain cases because of rounding errors.

If INPUT is a field of type P, internal calculatons similarly use packed numbers. This is expensive, but more accurate. If the calculation accuracy is very important, INPUT should thus be a field of type P.

Thanks,

Sriram Ponna.