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 check if a number has a floating point?

Former Member
0 Kudos

Hi all!

How do I check if a number has floating point (decimal number)?

Thanks!

1 ACCEPTED SOLUTION

JozsefSzikszai
Active Contributor
0 Kudos

there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.

7 REPLIES 7

Former Member
0 Kudos

Use CA statement.

Check this:

DATA: num(10) TYPE c VALUE '121212.00'.
IF num CA '.'.
  WRITE: 'YES'.
ELSE.
  WRITE: 'NO DECIMAL'.
ENDIF.

or you can do like this also.

DATA: num1 TYPE p decimals 2 VALUE '121212'.
DATA num2 TYPE i.
num2 =  num1.
IF num2 EQ num1.
  WRITE: 'NO DECIMAL'.
ELSE.
  WRITE: 'YES'.
ENDIF.

Thanks

JozsefSzikszai
Active Contributor
0 Kudos

there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.

0 Kudos

>

> there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.

How? Do you have some sample code? Thanks!

0 Kudos

Hello Ricardo,

Plz try this code:


v_int = trunc( v_num ).

IF v_int = v_num.
  WRITE: ' Number has no floating point '
ELSE.
  WRITE: ' Number has floating point '
ENDIF.

Hope this is clear.

BR,

Suhas

0 Kudos

>

> >

> > there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.

>

> How? Do you have some sample code? Thanks!

pls. use the code given by Suhas!

0 Kudos

>

> Hello Ricardo,

>

> Plz try this code:

>

>


> v_int = trunc( v_num ).
> 
> IF v_int = v_num.
>   WRITE: ' Number has no floating point '
> ELSE.
>   WRITE: ' Number has floating point '
> ENDIF.
> 

>

> Hope this is clear.

>

> BR,

> Suhas

Thanks Suhas! I used this and it worked.

Former Member
0 Kudos

Hi,

Try this,

data : var(10) TYPE c VALUE '1465.76'.

find '.' in var.

if sy-subrc = 0.

*check sy-subrc and do whatever u want

endif.