06-05-2008 9:33 AM
Hi,
I got an issue with decimal points in my program.
Here i don't want the decimal's to round.
For suppose i got a value of ' 8.3356', then i need only '8.33'.
But when we are trying to take the whole value into a value of type 'P' with decimals '2', it was considering as '8.34'.
Kindly suggest us the regarding.
Thanks and Regards,
Gopi.
06-05-2008 9:56 AM
try this code
here unit price is taken the way you need it without rounding
DATA: l_dec_part TYPE char18,
l_int_part TYPE char18,
int TYPE int2,
decimals TYPE int2.
CONSTANTS: l_c_1 TYPE char1 VALUE '1',
l_c_2 TYPE char1 VALUE '2',
l_c_3 TYPE char1 VALUE '3',
l_c_4 TYPE char1 VALUE '4',
l_c_0 TYPE char1 VALUE '0',
l_c_00 TYPE char3 VALUE '.00'.
take unit price uptotwo decimal places
SPLIT v_unit_pri AT '.' INTO l_int_part l_dec_part.
int = NUMOFCHAR( l_int_part ).
decimals = NUMOFCHAR( l_dec_part ).
IF decimals > l_c_2.
int = int + l_c_3.
IF v_unit_pri+int(1) > l_c_4.
v_unit_pri = v_unit_pri+0(int) + l_c_00.
ELSE.
v_unit_pri = v_unit_pri+0(int).
ENDIF.
ENDIF.
SHIFT v_unit_pri LEFT DELETING LEADING space.
IF decimals IS INITIAL.
CONCATENATE v_unit_pri l_c_00 INTO v_unit_pri.
ENDIF.
CLEAR: l_int_part, l_dec_part, int, decimals.
SPLIT v_unit_pri AT '.' INTO l_int_part l_dec_part.
int = NUMOFCHAR( l_int_part ).
decimals = NUMOFCHAR( l_dec_part ).
IF decimals = l_c_1.
CONCATENATE v_unit_pri l_c_0 INTO v_unit_pri.
ENDIF.
Try this out
it will surely help
thanks
Reward if useful
Richa
06-05-2008 9:35 AM
hi
use write edition,
in the below example
write :(4) '8.3356'.
or do like this
data : var(6) type c value '8.3356'.
write :/1(4) var .
regards
prasanth
Edited by: prasanth kasturi on Jun 5, 2008 10:55 AM
06-05-2008 9:56 AM
try this code
here unit price is taken the way you need it without rounding
DATA: l_dec_part TYPE char18,
l_int_part TYPE char18,
int TYPE int2,
decimals TYPE int2.
CONSTANTS: l_c_1 TYPE char1 VALUE '1',
l_c_2 TYPE char1 VALUE '2',
l_c_3 TYPE char1 VALUE '3',
l_c_4 TYPE char1 VALUE '4',
l_c_0 TYPE char1 VALUE '0',
l_c_00 TYPE char3 VALUE '.00'.
take unit price uptotwo decimal places
SPLIT v_unit_pri AT '.' INTO l_int_part l_dec_part.
int = NUMOFCHAR( l_int_part ).
decimals = NUMOFCHAR( l_dec_part ).
IF decimals > l_c_2.
int = int + l_c_3.
IF v_unit_pri+int(1) > l_c_4.
v_unit_pri = v_unit_pri+0(int) + l_c_00.
ELSE.
v_unit_pri = v_unit_pri+0(int).
ENDIF.
ENDIF.
SHIFT v_unit_pri LEFT DELETING LEADING space.
IF decimals IS INITIAL.
CONCATENATE v_unit_pri l_c_00 INTO v_unit_pri.
ENDIF.
CLEAR: l_int_part, l_dec_part, int, decimals.
SPLIT v_unit_pri AT '.' INTO l_int_part l_dec_part.
int = NUMOFCHAR( l_int_part ).
decimals = NUMOFCHAR( l_dec_part ).
IF decimals = l_c_1.
CONCATENATE v_unit_pri l_c_0 INTO v_unit_pri.
ENDIF.
Try this out
it will surely help
thanks
Reward if useful
Richa
06-05-2008 10:16 AM
Hi,
U can declare that variable as packed number.
It will round the fraction number as whole number.
DATA : M(5) TYPE i,
N(5) type p.
m = '2.365'.
N = M.
WRITE: n.
Thanks..................