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 off a value

Former Member
0 Likes
1,194

i have an amt field of currency type.

i want to round off the value like if the value is 2019.50 then it shud be

2020.00 . how can i do it..

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,134

try this

DATA: I TYPE I,

P TYPE P DECIMALS 2,

M TYPE F VALUE '-3.5',

D TYPE P DECIMALS 1.

I = CEIL( P ). " 4 - next largest whole number

I = CEIL( M ). " -3

I = FLOOR( P ). " 3 - next smallest whole number

I = FLOOR( M ). " -4

I = TRUNC( P ). " 3 - integer part

I = TRUNC( M ). " -3

D = FRAC( P ). " 0.5 - decimal part

D = FRAC( M ). " -0.5

regards

shiba dutta

i have an amt field of currency type.

i want to round off the value like if the value is 2019.50 then it shud be

2020.00 . how can i do it..

Thanks

7 REPLIES 7
Read only

Former Member
0 Likes
1,134

Hi

Use the aggregate function RND

RND(value).

Thanks

Read only

Former Member
0 Likes
1,135

try this

DATA: I TYPE I,

P TYPE P DECIMALS 2,

M TYPE F VALUE '-3.5',

D TYPE P DECIMALS 1.

I = CEIL( P ). " 4 - next largest whole number

I = CEIL( M ). " -3

I = FLOOR( P ). " 3 - next smallest whole number

I = FLOOR( M ). " -4

I = TRUNC( P ). " 3 - integer part

I = TRUNC( M ). " -3

D = FRAC( P ). " 0.5 - decimal part

D = FRAC( M ). " -0.5

regards

shiba dutta

Read only

0 Likes
1,134

Thanks for the post! Just what I needed!

Read only

Former Member
0 Likes
1,134

Hi

check the following Functions

following maths functionas are there in SAP:

<b>abs</b> -Absolute value of the argument arg

<b>sign-</b> 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.

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

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

<b>trunc-</b> Value of the integer part of the argument arg

<b>frac-</b> Value of the decimal places of the argument arg

Reward points if useful

Regards

Anji

Read only

Former Member
0 Likes
1,134

Hi,

hope u can use the function module ROUND.

Reward points if it is helpful.

Regards,

Sangeetha.

Read only

Former Member
0 Likes
1,134

Hi,

Use ROUND aggregate function.

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
1,134

1.

check the Fm Round_amount.

or ..

2.

logic has to be build this way

parameters : price like vbap-netwr .

data : val type i .

data : rem type p decimals 2.

rem = frac( price ).

rem = rem * 100.

if rem ge 50.

val = abs( price ).

move val to price.

write price.

else.

write:/ price.

endif.

like if the input is 2019.20 o/p will be 2019.20 only

if the input is 2019.51 o/p will be 2020.00.

check this .

3.

try the variation

write value curreny 'X' round 'Y' DECIMALS 'Z'.

CHECK this option as well.

Vijay