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 decimal

andy_dingfelder3
Participant
0 Likes
7,516

Hi all,

i´ve got a string with value 773,35999999 and wan´t them converted to 773,36. Anybody knows how to this.

In my test I always get problems with the comma ',' if it´s a point the following coding works:

DATA: p TYPE string VALUE '773.35999999',
      
v TYPE ZTEST123." ( ZTEST123 is dec15 decimals 2.)

v = p.

Any idea´s?

Thx, in advance,

Andy

1 ACCEPTED SOLUTION
Read only

matteo_montalto
Contributor
0 Likes
4,024

Yò Andy,

check this out:

replace all occurrences of ',' in yourcommanotation with '.' .

In alternative, you could check for some conversion FM, e.g. BAPI_CURRENCY_CONV_TO_EXTERNAL / INTERNAL, or PP_CATT_CONVERT_DECIMAL_POINT. But I guess the first one is the simplest way to obtain your desiderata.

5 REPLIES 5
Read only

Former Member
0 Likes
4,024

Hi,

replace , with . & try

Read only

matteo_montalto
Contributor
0 Likes
4,025

Yò Andy,

check this out:

replace all occurrences of ',' in yourcommanotation with '.' .

In alternative, you could check for some conversion FM, e.g. BAPI_CURRENCY_CONV_TO_EXTERNAL / INTERNAL, or PP_CATT_CONVERT_DECIMAL_POINT. But I guess the first one is the simplest way to obtain your desiderata.

Read only

Former Member
0 Likes
4,024

see.. comma is just a display pattern. the actual way how its stored is 100.00 not 100,00. this is a user display setting in SU01.

but still if you are getting , in place of . in the input string. replace this by a '.'.

as :

DATA: p1 TYPE string VALUE '773,35999999'.
data : p2 type p DECIMALS 2.
REPLACE FIRST OCCURRENCE OF ',' in p1 WITH '.'.
p2 = p1.
WRITE : p2.

Read only

Kanagaraja_L
Active Contributor
0 Likes
4,024

Is it possible ?

DATA: p TYPE string VALUE '773,35999999',
v TYPE p DECIMALS 2.
 REPLACE ALL OCCURRENCES OF ',' IN p WITH '.'.

v = p.

Kanagaraja L

Read only

Former Member
0 Likes
4,024

Hi Andy,

Just go through this link, I hjope it will help you.

[Link|;

Regards,

Nidhi Kothiyal