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

Remove decimals

Former Member
0 Likes
6,514

How do i remove the decimals from a variable?

If I have 40.587, I want it to become 40. And no rounding off.

16 REPLIES 16
Read only

Former Member
0 Likes
2,195

Hi,

Move the value to the variable of type P and display it.

Regards,

Senthil

Read only

0 Likes
2,195

data: f1 type p decimals 3 value '40.002'.

data:f2 type p.

f2 = f1.

write:f2.

Read only

Former Member
0 Likes
2,195

hi ,

declare the variable as type p decimals 0,

i think this will helpful.

thank.

Read only

0 Likes
2,195

I already did not using type p with or without decimals. But if I have 40.587 it will assign 40857 to the variable. Im getting the 40.587 from a table.

Read only

0 Likes
2,195

Hi Adrian,

Just goto the table name, then goto the field, double click the data element, then double click the domain. Check if there is any conversion routine for the field, if it exist double click that and use the FM in ur program.

Like this.

**CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

    • EXPORTING

    • input = v1

    • IMPORTING

    • OUTPUT = v3

  • .

*write 😕 v3.

The 'ALPHA_INPUT' should be the convers exit in the domain of your field.

Reward if helps.

Regards,

Senthil

Message was edited by: senthil kumar

Read only

former_member184495
Active Contributor
0 Likes
2,195

hi,

where ever you are outputting your value, add NO-DECIMALS NO-GAP,

cheers,

Aditya.

Read only

Former Member
0 Likes
2,195

Use the FM : HR_IN_ROUND_AMT

eXPORTING

AMOUNT : 40.587

RNDOFF : 100

RMDLMT : L

Read only

Former Member
0 Likes
2,195

hi,

data var1 type p decimals 3 value '20.455'.

data var2 type i.

move var1 to var2.

write : / var2. " 20

reward if useful...

Read only

0 Likes
2,195

I already did that. Using type I, but it just eliminates the period and put them all in the variable.

From 40.587 to 40587.

This is kinda weird...

Read only

0 Likes
2,195

Hi Adrian,

Did you try using the FLOOR function?

Regards,

Saurabh

Read only

0 Likes
2,195

Yes. I also use the floor function. the decimals keeps sticking to the value. Let's say 40.587, it becomes 40587.

Read only

0 Likes
2,195

one another concern:

<b>in that program attributes, check the field <u>FIXED POINT ARITHMETIC</u> is selected or not.

this check box should be selected,to get the exact values.</b>

REPORT ZSRIM_TEMP25.

data : v_p(12) type p decimals 3,

v_i type i.

v_p = '123.456'.

  • v_i = floor( v_p ).

v_i = trunc( v_p ).

write 😕 v_i.

you can use either FLOOR or TRUNC in this case,both will return numeric part of your variable to V_I.

here for both options,i am getting 123 to V_I variable.

Regards

srikanth

Message was edited by: Srikanth Kidambi

Read only

0 Likes
2,195

Hi Adrian,

In the Program attributes please check the checkbox 'Fixed Point Arithmetic'.

This should solve your problem (along with using the FLOOR function).

Hope this helps!

Regards,

Saurabh

Read only

Former Member
0 Likes
2,195

Hi Adrian,

You can use the FLOOR function.

eg.

DATA : w_num type p decimals 3 value '40.587',

w_num_i type i.

w_num_i = FLOOR( w_num ).

Now w_num_i will contain 40.

Hope this helps!

Regards,

Saurabh

Read only

Former Member
0 Likes
2,195

as Srikanth pointed out in ur program

goto>attributes> check Fixed point arithmetic,

<b>Fixed point arithmetic</b>

If you mark this checkbox, all caluculations in the program will use fixed point arithmetic.

If you do not, packed numbers (ABAP/4 type P, Dictionary types CURR, DEC or QUAN) will be treated as integers when they are used in assignments, comparisons and calculations, irrespective of the number of decimal places defined. Intermediate results in arithmetic calculations will also be rounded to the next whole number. The number of decimal places defined is only taken into account when you output the answer using the WRITE statement.

this will work

REPORT ZSPELL.

data : v_amt type p decimals 2 value '40.58',
       v_int type i.

v_int = floor( v_amt ).

write : v_int.

Message was edited by: Chandrasekhar Jagarlamudi

Read only

Former Member
0 Likes
2,195

data: c1 type p decimals 2.