Application Development 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: 

Problem with Decimals

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

3 REPLIES 3

prasanth_kasturi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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..................