Application Development 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: 

Convert string to float

0 Kudos

in this code output will be

i want

DATA v_str TYPESTRINGVALUE'123,456,789,123.456'.

DATA v_flt TYPE F.WRITE:/'String :', v_str."With Commas

REPLACEALLOCCURRENCESOF','IN v_str WITH''.

WRITE:/'String :', v_str."Without Commas

CATCHSYSTEM-EXCEPTIONS ARITHMETIC_ERRORS =1

CONVERSION_ERRORS =2.

MOVE v_str TO v_flt.ENDCATCH.

WRITE:/'Float :', v_flt."Float value

4 REPLIES 4

p190355
Active Contributor

Have you checked the user settings; The output format is based on what the defaults is set to

matt
Active Contributor
0 Kudos

Looks like the decimal comma.

Sandra_Rossi
Active Contributor

Think to split the problem in smaller units.

So your first question is to remove the blanks in STRING so that to get 123456789123.456

marcobeer
Active Participant
0 Kudos

Hello Symbat,

Here's a page which explains several ways of converting strings to numbers. For your question, Method 1 in the second block seems to be fitting very well:

https://sap4tech.net/convert-string-number-string-abap/amp/#method-1-with-abap-coding-the-statement

Best Regards

Marco