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

rounding values

Former Member
0 Likes
601

By dividing a large number of value iam getting value in a variable eg.

A = 56.356337763383736373

I want to convert this A to 2 decimal places . can anyone help me in this.

Thanks.

5 REPLIES 5
Read only

Former Member
0 Likes
580

Hi Joseph,

Check this info.

<b>Round values up to nears value</b>

The ROUND' command only rounds to nearest value whether it be up or down.

Therfore the following code demonstrates how to always round a number UP 1 or 2 decimal places.

*Rounds a value UP to 2 decimal places

REPORT zround2.

PARAMETER: p_value type p decimals 3 default '22.123'.

DATA: d_value type p decimals 2,

d_int1 TYPE i,

d_int2 TYPE i,

d_number(20) TYPE c,

d_num_result(20) TYPE c,

d_decimal(2) TYPE c.

************************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

d_number = p_value.

SHIFT d_number LEFT UP TO '.'.

SHIFT d_number LEFT.

d_decimal = d_number+0(2).

d_decimal = d_decimal + 1.

Clear: d_number.

d_number = p_value.

SHIFT d_number RIGHT DELETING TRAILING '123456789 '.

SHIFT d_number LEFT DELETING LEADING ' '.

CONCATENATE d_number d_decimal INTO d_num_result.

d_value = d_num_result.

write:/ 'Value rounded up to 2 decimal places is ', d_value.

Hope this resolves your query.

Reward all the helpful answers.

Regards

Read only

Former Member
0 Likes
580

declare A as

data: A(10) type p decimals 2.

Read only

Former Member
0 Likes
580

Hi,

Declare a varible

data : var TYPE p DECIMALS 2.

and move that value to this variable.

Regards,

Balavardhan.K

Read only

Former Member
0 Likes
580

Hi,

DATA pack TYPE p VALUE '123.456'

DECIMALS 3.

WRITE pack DECIMALS 2.

WRITE: / pack ROUND -2,

/ pack ROUND -1,

/ pack ROUND 1,

/ pack ROUND 2.

check out the link given below

http://www.sapdevelopment.co.uk/tips/dataman/tips_roundup.htm

Prajith

Read only

Former Member
0 Likes
580

Hi Joseph,

Declare another variable B as TYPE P with 2 decimals.

<b>DATA B TYPE P DECIMALS 2.</b>

<b>B = A.

WRITE:/ B.</b>

Thanks,

Vinay