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: 

How to read number of digits in a given decimal number by using abap

Former Member
0 Kudos

Hi ,

How can we read the number of digits present in a decimal number , just before decimal.

For example: I have this number - 200.00

Now I want to read how many digits are present in this number before decimal ( . ) point. so in this case the number of digits are 3( 200). Similarly if we have a number 15.00, in this case number of digits is 2 ( 15 ) before decimal point.

How can i acheive this by using abap.

Regards

PG

1 ACCEPTED SOLUTION

alespad
Contributor
0 Kudos

Hi Pg,

you can try this code:

DATA: decimal(3) type p decimals 2,
        no_decimal type i,
        no_dec_char(10),
        len type i.

START-OF-SELECTION.


decimal = '200.24'.
no_decimal = decimal.

no_dec_char = no_decimal.

condense no_dec_char no-gaps.
len = strlen( no_dec_char ).

6 REPLIES 6

alespad
Contributor
0 Kudos

Hi Pg,

you can try this code:

DATA: decimal(3) type p decimals 2,
        no_decimal type i,
        no_dec_char(10),
        len type i.

START-OF-SELECTION.


decimal = '200.24'.
no_decimal = decimal.

no_dec_char = no_decimal.

condense no_dec_char no-gaps.
len = strlen( no_dec_char ).

Former Member
0 Kudos

Hi alessandro

Thanks for the reply.

It did wok!

Danke schon.

Regards

PG

Former Member
0 Kudos

Hi

try this

suppose your variable v_data has value as 200.20

declare new variable v_data1.

use split statement as below

split v_data at '.' into v_data1.

hope this will work.

Thanks

LG

Edited by: LalitG on Mar 23, 2011 10:26 AM

Former Member
0 Kudos

Hi

try this

suppose your variable v_data has value as 200.20

declare new variable v_data1.

use split statement as below

split v_data at '.' into v_data1.

and then you can find the length of v_data1 using STRLN

then write your write statement to print the result.

hope this will work.

Thanks

LG

0 Kudos

Hi !

Chcek this FM SWA_DETERMINE_DECIMALS...

Former Member
0 Kudos

Hi

There are differenent logics available.The previous reply was really good. get another way also.

Data: v_dec type p decimals 3,

v_temp type char20,

v1 type char10,

v2 type char10,

v_len type i.

v_temp = v_dec.

split v_dec at '.' into v1 v2 .

condense v1 no-gaps.

len = strlen( v1 ).

Regards,

Chellamma Chandrasekar.