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

Former Member
0 Likes
928

Hi all,

I am making some division as follows.

data: a type p decimals 2,

b(2) type c,

a = ( 62 / 13 ).

write a decimals 0 to b.

b = b + 1.

It returns the value 4.77 to a

while adding it gets rounded off to 5 and then further addition is done.

But as per my requirement, I want only the value 4 irrespective of decimals i.e. the result without rounded off .

Pls. help me.

Thanks in advance.

9 REPLIES 9
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
894

Hi,

data: a type p decimals 2,

b(2) type c,

a = ( 62 / 13 ).

a = trunc( a ).

Read only

Former Member
0 Likes
894

Hi Shravani,

Then you can go with statement called FLOOR , It will help you.

Reward point if it is helpful

Regards,

Kiran I

Read only

Former Member
0 Likes
894

Hi,

please use a= (62 DIV 14) to receive the value.

See transaction abapterm search word DIV for further details.

DIV is an arithmetic operand in sap.

Hth

Ute

Read only

Former Member
0 Likes
894

Hi,

U can use <b>floor</b> function as given below.

FLOOR( X ) :

Largest integer value that is not greater than x

data: a type p decimals 2,

b(2) type c.

a = ( 62 / 13 ).

b = floor( a ).

write b.

Read only

Former Member
0 Likes
894

Hi Shravani ,

Use the command FLOOR.

Here is the modified code

data: a type p decimals 2,
b(2) type c.
a = ( 62 / 13 ).
a = FLOOR( a ).  " Code Added
write a decimals 0 to b.
b = b + 1.

write: b.

Regards

Arun

  • Assign Points for helpful reply

Read only

0 Likes
894

use as ur requerment for rounding..

check this example...

DATA: I TYPE I,

P TYPE P DECIMALS 2,

M TYPE F VALUE '-3.5',

D TYPE P DECIMALS 1.

P = ABS( M ). " 3,5

I = P. " 4 - business rounding

I = M. " -4

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

Read only

former_member508729
Active Participant
0 Likes
894

Hi Shrawani,

see below code.

DATA: a TYPE p DECIMALS 2,

b(2) TYPE c.

a = ( 62 / 13 ).

a = TRUNC( a ).

WRITE a DECIMALS 0 TO b.

b = b + 1.

it will work.

Regards

Ashutosh

Reward points if helpful

Read only

Former Member
0 Likes
894

use the fn FLOOR

data i type i.

data p type p decimals 2 value '3.7'.

compute i = FLOOR( p ).

now i contains 3 now.

regards

shiba dutta

Read only

Former Member
0 Likes
894

It worked out.

Thank You Very Much.