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

Rounded value

Former Member
0 Likes
1,270

Hi Experts,

I displayed one field, it containe data like 1.0004,2.546,4.508etc...

Here it displayed only rounded value like 1,1.5,2,2.5,3,3.5 values.

How can i display.

Please tell me the code

5 REPLIES 5
Read only

Former Member
0 Likes
979

HI

check the type of the field in field declaration.

Regards

Megha Sharma

Read only

Former Member
0 Likes
979

Hi,

1.Declare a variable with reference to Packed decimal.

like DATA: v_round type p decimal 1.

2.If you need rounding the value use u can use the FM ROUND

Rounding to spec. no. of dec. place (round up, round down, comm. round

Functionality

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

Example

The value VALUE is to be rounded up to the nearest hundred.

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.

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.

Regards,

Shiva Kumar

Read only

Former Member
0 Likes
979

Hi,

Declare the field like this.

parameters : v_num type P decimals 1.

or

Use these FUnctions.

ROUND

CEIL

FLOOR

regards

Sandeep Reddy.

Read only

Former Member
0 Likes
979

Hi,

Even if you declare in packaged decimal(P) with decimal addition the value gets approaximated at the time of assignment to the variable of type P. You keep your result of type i only.Thereafter u write your result to a character variable and display that character variable. It will display accurate value.

sample code:

data: op1 type i value 23,

op2 type i value 22,

result_i type i,

result_c(20) type c.

result_i = op1/op1.

write result_i to result_c.

condense result_c.

pls give points if helpfull.

Read only

Former Member
0 Likes
979

check the data type of the field declared...it must be of type ie rounded to result u are getting

declare the field of type say char

followin code will help you...here unit price is declared of type char not NETWR so it can be rounded to desired no of places

\as we hv done it for three decimal places

        • Round Off the unit price after three decimal places

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_5 TYPE char1 VALUE '5',

l_c_001 TYPE char4 VALUE '.001',

l_c_0 TYPE char1 VALUE '0',

l_c_00 TYPE char3 VALUE '.00'.

SPLIT v_unitprice 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_4.

IF v_unitprice+int(1) > l_c_5.

v_unitprice = v_unitprice+0(int) + l_c_001.

ELSE.

v_unitprice = v_unitprice+0(int).

ENDIF.

ENDIF.

SHIFT v_unitprice LEFT DELETING LEADING space.

IF decimals IS INITIAL.

CONCATENATE v_unitprice l_c_00 INTO v_unitprice.

ENDIF.

CLEAR: l_int_part, l_dec_part, int, decimals.

SPLIT v_unitprice 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_unitprice l_c_0 INTO v_unitprice.

ENDIF.

IF decimals = l_c_2.

CONCATENATE v_unitprice l_c_0 INTO v_unitprice.

ENDIF.

End of change <C62963> by <SAZK>(Richa Khosla)

data : l_wa_price type /fir/ro2c0bgs_pric_sub_totals.

  • Fetch the value of Price table with key item No.

clear : l_wa_price.

read table it_price into l_wa_price with key posnr = wa_output-itm_no .

If SY-SUBRC is INITIAL.

if sy-subrc = 0.

v_amount = l_wa_price-netwr.

v_amt1 = l_wa_price-netwr.

v_unitprice = l_wa_price-netwr / wa_output-tntgew .

endif.

try this..it will surely help

Reward points if useful

Thanks

Edited by: Richa Khosla on May 28, 2008 7:15 AM