2006 Nov 07 9:29 PM
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
2006 Nov 08 9:18 PM
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
2006 Nov 07 9:31 PM
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
2006 Nov 07 9:33 PM
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
2006 Nov 07 9:34 PM
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
2006 Nov 07 10:06 PM
Assign it to an integer field.
Or take the value as integer from begining and you will not get the .000
Prince
2006 Nov 08 2:35 PM
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
2006 Nov 08 9:06 PM
Hi priyanka,
Try this
shift v_num right deleting trailing '0'.
Revert back for more help
Regards
Naresh
2006 Nov 08 9:18 PM
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
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |