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 zero after decimal point

Former Member
0 Likes
8,952

Hi all sap master.

i want to ask how to remove zero after decimal point in abap code?

I have code like this

DATA: numb(13) TYPE c VALUE '12123.010'.

SHIFT numb RIGHT DELETING TRAILING '0'.

WRITE: numb.

But its not work.

Any clue?

Thank and regard

7 REPLIES 7
Read only

Former Member
0 Likes
2,461

How about this?

DATA: l_field1 TYPE string,

       l_field2 TYPE string.

DATA: numb(13) TYPE c VALUE '12123.010'.

SPLIT numb AT '.' INTO l_field1 l_field2.

REPLACE ALL OCCURRENCES OF '0' IN l_field2 WITH space.

CONDENSE l_field2.

CONCATENATE l_field1 l_field2 INTO l_field1 SEPARATED BY '.'.

WRITE l_field1.

Read only

0 Likes
2,461

i dont want remove all zero after decimal point.

The result from your eg the output like this 12123.1

This mean the amount different.

If i want output like this 12.123,01?

Any clue?

Thanks and regard

Read only

0 Likes
2,461

Then do this instead:

(Remove replace all occurence and replace with shift)

DATA: l_field1 TYPE string,

       l_field2 TYPE string.

DATA: numb(13) TYPE c VALUE '12123.010'.

SPLIT numb AT '.' INTO l_field1 l_field2.

SHIFT l_field2 RIGHT DELETING TRAILING '0'.

CONDENSE l_field2.

CONCATENATE l_field1 l_field2 INTO l_field1 SEPARATED BY '.'.

WRITE l_field1.

Read only

0 Likes
2,461

Do you want to convert decimal notation format from 12,123.010(,.) to 12.123,01(.,) and remove trailing 0 after the decimals?

If yes, in addition to Elzkie's code above, add additional TRANSLATE statement as below.

DATA: l_field1 TYPE string,

         l_field2 TYPE string.

DATA: numb(13) TYPE c VALUE '12,123.010'.

SPLIT numb AT '.' INTO l_field1 l_field2.

SHIFT l_field2 RIGHT DELETING TRAILING '0'.

CONDENSE l_field2.

CONCATENATE l_field1 l_field2 INTO l_field1 SEPARATED BY '.'.


TRANSLATE l_field1 USING ',..,'.

WRITE l_field1.

Regards,

Thanga

Read only

0 Likes
2,461

Hi thanga

yes i want.

Like i want. Thank you so much

Read only

rosenberg_eitan
Active Contributor
0 Likes
2,461

Hi,

Try this please:

FORM test_06 .

  DATA: numb TYPE p DECIMALS 2 VALUE '12123.010' . " Data: numb of type Packed Number

  DATA: buffer TYPE c LENGTH 20 . " Data: buffer of type Character

  WRITE numb TO buffer LEFT-JUSTIFIED NO-GROUPING DECIMALS 0  .

ENDFORM . "test_06

Regards.

Read only

Velu
Explorer
0 Likes
2,461

Hello,

Try the below piece of code and it should work in your case.

DATA: v_var1(13) TYPE c.

v_var1 = '12,123.010'.

REPLACE ALL OCCURRENCES OF '.' IN v_var1 WITH '-'.

REPLACE ALL OCCURRENCES OF ',' IN v_var1 WITH '.'.

REPLACE ALL OCCURRENCES OF '-' IN v_var1 WITH ','.

SHIFT v_var1 RIGHT DELETING TRAILING '0'.

WRITE: v_var1.


If it you declare the variable as a Quantity data type, then you can change the below setting to achieve the same.


System->User Profile->Own data