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

Number Rounding

Former Member
0 Likes
966

Hi Friends,

Pls tell me how to round a number to given digit.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
916

hi,

Pass it to type P Variable.

i,e,

<b>data: var type P decimals 2.</b>

Regards,

Santosh

8 REPLIES 8
Read only

Former Member
0 Likes
916

Effect of different ROUND specifications:

DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.

WRITE: /X ROUND -2, "output: 1,249,397.00

/X ROUND 0, "output: 12,493.97

/X ROUND 2, "output: 124.94

/X ROUND 5, "output: 0.12

Read only

Former Member
0 Likes
916

Hi,

Data : num type i.

num = round (given_num).

Thanks

sandeep

Reward if helpful

Read only

Former Member
0 Likes
917

hi,

Pass it to type P Variable.

i,e,

<b>data: var type P decimals 2.</b>

Regards,

Santosh

Read only

Former Member
0 Likes
916

Hi

see this Maths functions and try doing them.

abs -Absolute value of the argument arg

sign- Plus/minus sign of the argument arg: -1, if the value of arg is negative; 0 if the value of arg is 0; 1 if the value of arg is positive.

ceil -Smallest integer number that is not smaller than the value of the argument arg.

floor- Largest integer number that is not larger than the value of the argument arg.

trunc- Value of the integer part of the argument arg

frac- Value of the decimal places of the argument arg

Reward points if useful

Regards

Anji

Read only

dev_parbutteea
Active Contributor
0 Likes
916

hi,

try these simple codes:

DATA :

varxx type p LENGTH 4 DECIMALS 2 VALUE '2.96' ,

varx2 type p LENGTH 4 DECIMALS 2 VALUE '2.46' ,

vari1 TYPE n LENGTH 4,

vari2 TYPE n LENGTH 4,

num TYPE n LENGTH 4.

WRITE varxx to vari1 DECIMALS 0.

WRITE varx2 to vari2 DECIMALS 0.

WRITE:/ varxx , ' ', vari1.

WRITE:/ varx2 , ' ', vari2.

Regards,

Sooness

Read only

Former Member
0 Likes
916

Hi,

Use ROUND function, Number is rounded up or down during conversion. The different formats of ROUND are:

ROUND <r> : Type P fields are multiplied by 10**(-r) and then rounded.

Ex:

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.

Output:

123,46

12.345,600

1.234,560

12,346

1,235

Regards,

Bhaskar

Read only

Former Member
0 Likes
916

Hello,

In case of pricing procedure, you can tackle this by using standard routine in your pricing procedure.

In the 'Caltype' column in pricing that is "Condition formula for alternative calculation type", you need to add routine number "17 Rounding as perT001R", before those excise conditions which you want rounded.

Additionally, in table T001R such rounding data should be maintained.

For this goto SPRO - SAP NetWeaver - General Settings - Currencies - Define rounding rules for currencies

here maintain: Co, Code + Currency = 100

Additionally you can convey this to your consultant

This will solve your problem

Regards

Dhananjay

Read only

Former Member
0 Likes
916

hi

use floor statement or Fm Round

for Fm ROUND refer to its documentation for better understanding

and for Statement floor . Put an cursur over it in abap editor and press F1 u fet the documentaion of it .

Cheers

Snehi

Edited by: snehi chouhan on Sep 2, 2008 8:21 AM