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

Convert string to float

Former Member
0 Likes
2,630

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
Read only

RemiKaimal
Active Contributor
2,441

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

Read only

matt
Active Contributor
0 Likes
2,441

Looks like the decimal comma.

Read only

Sandra_Rossi
Active Contributor
2,441

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

Read only

Marco_Flamm
Active Participant
0 Likes
2,441

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