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

decimal number

Former Member
0 Likes
1,044

if a number contains all zeros after decimal number how to round it .

ex

i/p : 1.000

o/p : 1

i/p : 0.000

o/p : 0

I appreciate your response

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,005

Hi,

Check this..

DATA: I TYPE I.

DATA: P TYPE P DECIMALS 3.

DATA: MOD TYPE I.

P = '12.000'.

I = P.

P = P * 1000.

I = I * 1000.

MOD = P MOD I.

IF MOD IS INITIAL.

I = I / 1000.

WRITE: / I.

ELSE.

P = P / 1000.

WRITE: / P.

ENDIF.

If you give P = '12.500', it will display 12.500..

If you give P = '12.000', it will display 12

Thanks,

Naren

if a number contains all zeros after decimal number how to round it .

ex

i/p : 1.000

o/p : 1

i/p : 0.000

o/p : 0

I appreciate your response

7 REPLIES 7
Read only

Former Member
0 Likes
1,005

You can just write it to an integer field.

REPORT ztest MESSAGE-ID 00.

DATA: dec_f(7) TYPE p DECIMALS 2 VALUE '12.000',
      int_f TYPE i.

MOVE dec_f TO int_f.

WRITE: /001 dec_f, int_f.

Rob

Message was edited by: Rob Burbank

Read only

Former Member
0 Likes
1,005

Hi,

Assign it to a integer field..

DATA: V_INT TYPE INT4.

DATA: V_QTY TYPE MENGE_D VALUE '1.000'.

V_INT = V_QTY.

WRITE: / V_INT.

Thanks,

Naren

Read only

Former Member
0 Likes
1,005

Hi,

You can also use FM ROUND.


data: wa_input  type i,      
      wa_output type i.

wa_input = '1.000'.

CALL FUNCTION 'ROUND'  
  EXPORTING    
    INPUT              = wa_input 
  IMPORTING   
    OUTPUT             = wa_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:/ wa_output.

Hope this will help.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,005

Assign it to an integer field.

Or take the value as integer from begining and you will not get the .000

Prince

Read only

0 Likes
1,005

If the decimal number contains zeros after decimal point the integer part of that should be printed otherwise it should be printed as a decimal number itself.

ex : 12.500

o/p :12.5 or 12.500

i/p : 12.000

o/p : 12

and how to avoid the spaces before the number

Read only

Former Member
0 Likes
1,005

Hi priyanka,

Try this

shift v_num right deleting trailing '0'.

Revert back for more help

Regards

Naresh

Read only

Former Member
0 Likes
1,006

Hi,

Check this..

DATA: I TYPE I.

DATA: P TYPE P DECIMALS 3.

DATA: MOD TYPE I.

P = '12.000'.

I = P.

P = P * 1000.

I = I * 1000.

MOD = P MOD I.

IF MOD IS INITIAL.

I = I / 1000.

WRITE: / I.

ELSE.

P = P / 1000.

WRITE: / P.

ENDIF.

If you give P = '12.500', it will display 12.500..

If you give P = '12.000', it will display 12

Thanks,

Naren